Merge pull request #3149 from rectorphp/fix-sniff-public

fix sniff public
This commit is contained in:
Tomas Votruba 2020-04-08 16:48:43 +02:00 committed by GitHub
commit 38700fa90f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 112 additions and 12 deletions

View File

@ -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');
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
abstract class SkipAbstract
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
use PhpParser\NodeTraverser;

View File

@ -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
{

View File

@ -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
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
class SkipExternalFetch
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
class SkipInterfaceImplemented
{

View File

@ -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;

View File

@ -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.
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
trait SkipTrait
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;
class SkipUsedInTrait
{

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.
}
}

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace PHP_CodeSniffer\Sniffs;
if (interface_exists('PHP_CodeSniffer\Sniffs\Sniff')) {
return;
}
interface Sniff
{
}