fix sniff fro ChangeReadOnlyPropertyWithDefaultValueToConstantRector

This commit is contained in:
TomasVotruba 2020-04-08 16:44:11 +02:00
parent d375cdc6f3
commit 22a55b85e1
2 changed files with 47 additions and 1 deletions

View File

@ -99,7 +99,7 @@ PHP
*/
public function refactor(Node $node): ?Node
{
if (count($node->props) !== 1) {
if ($this->shouldSkip($node)) {
return null;
}
@ -185,4 +185,18 @@ PHP
return false;
}
private function shouldSkip(Property $property): bool
{
if (count($property->props) !== 1) {
return true;
}
$class = $property->getAttribute(AttributeKey::CLASS_NODE);
if (! $class instanceof Class_) {
return false;
}
return $this->isObjectType($class, 'PHP_CodeSniffer\Sniffs\Sniff');
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Rector\SOLID\Tests\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector\Fixture;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
final class SkipSniff implements Sniff
{
/**
* @var string[]
*/
private $magicMethods = [
];
public function run()
{
foreach ($this->magicMethods as $magicMethod) {
echo $magicMethod;
}
}
public function register()
{
// TODO: Implement register() method.
}
public function process(File $phpcsFile, $stackPtr)
{
// TODO: Implement process() method.
}
}