mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
Merge pull request #3149 from rectorphp/fix-sniff-public
fix sniff public
This commit is contained in:
commit
38700fa90f
@ -124,7 +124,6 @@ PHP
|
||||
private function shouldSkip(Property $property): bool
|
||||
{
|
||||
$classNode = $property->getAttribute(AttributeKey::CLASS_NODE);
|
||||
|
||||
if ($this->shouldSkipClass($classNode)) {
|
||||
return true;
|
||||
}
|
||||
@ -178,6 +177,10 @@ PHP
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->isObjectType($classLike, TestCase::class);
|
||||
if ($this->isObjectType($classLike, TestCase::class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->isObjectType($classLike, 'PHP_CodeSniffer\Sniffs\Sniff');
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
abstract class SkipAbstract
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
use PhpParser\NodeTraverser;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
final class SkipChildPropertyUsage extends AbstractWithTearDown
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
class SkipClassExtended extends AbstractParentClass
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
class SkipExternalFetch
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
class SkipInterfaceImplemented
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
|
||||
final class SkipSniff implements Sniff
|
||||
{
|
||||
public $sniffConfigProperty;
|
||||
|
||||
public function shouldSkip(string $methodName, string $className): bool
|
||||
{
|
||||
// not really a setter, but usually test "setup" method
|
||||
if ($methodName === 'setUp') {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->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.
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
trait SkipTrait
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
|
||||
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
|
||||
|
||||
class SkipUsedInTrait
|
||||
{
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
}
|
||||
}
|
14
stubs/PHP_CodeSniffer/Sniffs/Sniff.php
Normal file
14
stubs/PHP_CodeSniffer/Sniffs/Sniff.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PHP_CodeSniffer\Sniffs;
|
||||
|
||||
if (interface_exists('PHP_CodeSniffer\Sniffs\Sniff')) {
|
||||
return;
|
||||
}
|
||||
|
||||
interface Sniff
|
||||
{
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user