Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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');
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;

abstract class SkipAbstract
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;

use PhpParser\NodeTraverser;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;

class SkipExternalFetch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;

class SkipInterfaceImplemented
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;

trait SkipTrait
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalOnlyMethodRector\Fixture;
namespace Rector\Privatization\Tests\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector\Fixture;

class SkipUsedInTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if (count($node->props) !== 1) {
if ($this->shouldSkip($node)) {
return null;
}

Expand Down Expand Up @@ -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');
}
}
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions stubs/PHP_CodeSniffer/Sniffs/Sniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace PHP_CodeSniffer\Sniffs;

if (interface_exists('PHP_CodeSniffer\Sniffs\Sniff')) {
return;
}

interface Sniff
{

}