#26: Add Sniff for Getters not change state#57
Closed
larsroettig wants to merge 6 commits intodevelopfrom
Closed
Conversation
Contributor
|
Could you please commit |
Member
Author
|
@lenaorobei done 😸 |
lenaorobei
previously approved these changes
Mar 8, 2019
lenaorobei
reviewed
Mar 8, 2019
lenaorobei
previously approved these changes
Mar 8, 2019
paliarush
previously approved these changes
Mar 8, 2019
Need to take property caching into account.
Member
Author
|
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);
}
} |
Member
Author
|
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;
}; |
magento-devops-reposync-svc
pushed a commit
that referenced
this pull request
Sep 7, 2021
…-coding-standard-264 [Imported] Version 9 master update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
see #26