-
Notifications
You must be signed in to change notification settings - Fork 160
#26: Add Sniff for Getters not change state #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Could you please commit |
@lenaorobei done 😸 |
Need to take property caching into account.
Hi @lenaorobei, Conditions:
Possbily Solutions
See my Example: <?php
namespace Foo\Bar;
class SizeService
{
/**
* @return int
*/
public function getSize()
{
// some implementation
return 12;
}
/**
* @param $size
* @return void
*/
public function setSize($size)
{
// some implementation
}
}
interface SizeServiceInterface
{
/**
* @return int
*/
public function getSize();
/**
* @param $size
* @return void
*/
public function setSize($size);
}
class SizeServiceFacade implements SizeServiceInterface
{
/**
* @var int
*/
private $size;
/**
* @var SizeService
*/
private $service;
/**
* @param SizeService $service
*/
public function __construct(SizeServiceInterface $service)
{
$this->service = $service;
}
/**
* @return int
*/
public function getSize()
{
if ($this->size === null) {
$this->size = $this->service->getSize();
}
return $this->size;
}
/**
* @return void
*/
public function setSize($size)
{
$this->size = $size;
$this->service->setSize($size);
}
} |
Hi @paliarush and @lenaorobei, Testcase: <?php
namespace Foo\Bar;
abstract class Bar
{
public static $foobar = 100;
}
class Foo extends Bar
{
/**
* @var int
*/
private static $staticProperty;
/**
* @var int
*/
private $property;
/**
* @return int
*/
public function getStaticProperty()
{
self::$staticProperty = 12;
static::$staticProperty -= 12;
self::$staticProperty .= 12;
return self::$staticProperty;
}
/**
* @return int
*/
public function getProperty()
{
if (true) {
}
$this->property = 1223;
return $this->property;
}
/**
* @return int
*/
public function getPropertyCached()
{
if ($this->property === null) {
$this->property = 1223;
}
return $this->property;
}
public function getPropertyLocal()
{
$local = $this->property;
$localArray = [
'payment' => [
'test' => [
'isActive' => $this->config->isActive(),
'title' => $this->config->getTitle()
]
]
];
return $this->property;
}
private function getSalesChannelForOrder($order)
{
$websiteId = (int)$order->getStore()->getWebsiteId();
$websiteCode = $this->websiteRepository->getById($websiteId)->getCode();
return $this->salesChannelFactory->create([
'data' => [
'type' => '',
'code' => $websiteCode
]
]);
}
const MODE_AUTO = 0;
const MODE_MANUAL = 1;
public function getOptionsArray()
{
return [
self::MODE_AUTO => __('Automatically'),
self::MODE_MANUAL => __('Manually')
];
}
public function testigetFoo()
{
$this->property = 1223;
return $this->property;
}
/**
* @return int
*/
public function normalMethod()
{
$localVariable = 12;
return $localVariable;
}
public function getStorageModel($storage = null, $params = [])
{
if ($storage === null) {
$storage = $this->_coreFileStorage->getCurrentStorageCode();
}
switch ($storage) {
case self::STORAGE_MEDIA_FILE_SYSTEM:
$model = $this->_fileFactory->create();
break;
default:
return false;
}
if (isset($params['init']) && $params['init']) {
$model->init();
}
return $model;
}
}
$d = function ($test) {
$test = 123;
}; |
…-coding-standard-264 [Imported] Version 9 master update
see #26