diff --git a/rules/privatization/src/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php b/rules/privatization/src/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php index 37bb15600596..3bfd28943bb0 100644 --- a/rules/privatization/src/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php +++ b/rules/privatization/src/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php @@ -124,7 +124,6 @@ public function refactor(Node $node): ?Node private function shouldSkip(Property $property): bool { $classNode = $property->getAttribute(AttributeKey::CLASS_NODE); - if ($this->shouldSkipClass($classNode)) { return true; } @@ -178,6 +177,10 @@ private function shouldSkipClass(?ClassLike $classLike): bool return true; } - return $this->isObjectType($classLike, TestCase::class); + if ($this->isObjectType($classLike, TestCase::class)) { + return true; + } + + return $this->isObjectType($classLike, 'PHP_CodeSniffer\Sniffs\Sniff'); } } diff --git a/rules/privatization/tests/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/skip_abstract.php.inc b/rules/privatization/tests/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/skip_abstract.php.inc index f376d2c53e57..2ec5ec1bfa8f 100644 --- a/rules/privatization/tests/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/skip_abstract.php.inc +++ b/rules/privatization/tests/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/skip_abstract.php.inc @@ -1,6 +1,6 @@ sniffConfigProperty as $allowedClass) { + if (fnmatch($allowedClass, $className, FNM_NOESCAPE)) { + return true; + } + } + + return false; + } + + public function register() + { + // TODO: Implement register() method. + } + + public function process(File $phpcsFile, $stackPtr) + { + // TODO: Implement process() method. + } +} diff --git a/rules/privatization/tests/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/skip_trait.php.inc b/rules/privatization/tests/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/skip_trait.php.inc index 50f08b01557a..ed767a427221 100644 --- a/rules/privatization/tests/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/skip_trait.php.inc +++ b/rules/privatization/tests/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/skip_trait.php.inc @@ -1,6 +1,6 @@ props) !== 1) { + if ($this->shouldSkip($node)) { return null; } @@ -185,4 +185,18 @@ private function isLocalPropertyFetch(Node $node): bool 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'); + } } diff --git a/rules/solid/tests/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector/Fixture/skip_sniff.php.inc b/rules/solid/tests/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector/Fixture/skip_sniff.php.inc new file mode 100644 index 000000000000..d6910e92274b --- /dev/null +++ b/rules/solid/tests/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector/Fixture/skip_sniff.php.inc @@ -0,0 +1,32 @@ +magicMethods as $magicMethod) { + echo $magicMethod; + } + } + + public function register() + { + // TODO: Implement register() method. + } + + public function process(File $phpcsFile, $stackPtr) + { + // TODO: Implement process() method. + } +} diff --git a/stubs/PHP_CodeSniffer/Sniffs/Sniff.php b/stubs/PHP_CodeSniffer/Sniffs/Sniff.php new file mode 100644 index 000000000000..d489f6eab96b --- /dev/null +++ b/stubs/PHP_CodeSniffer/Sniffs/Sniff.php @@ -0,0 +1,14 @@ +