[Removing] Move RemoveInterfacesRector here (#5361)

This commit is contained in:
Tomas Votruba 2021-01-29 11:38:59 +01:00 committed by GitHub
parent 53102c9c29
commit f1a70bd271
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 392 additions and 358 deletions

View File

@ -3,8 +3,8 @@
declare(strict_types=1);
use PHPStan\Type\ObjectType;
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Removing\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Removing\ValueObject\ArgumentRemover;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

View File

@ -5,13 +5,13 @@ declare(strict_types=1);
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
use Rector\Generic\ValueObject\ArgumentAdder;
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Laravel\Rector\Class_\AddMockConsoleOutputFalseToConsoleTestsRector;
use Rector\Laravel\Rector\ClassMethod\AddParentBootToModelClassMethodRector;
use Rector\Laravel\Rector\MethodCall\ChangeQueryWhereDateValueWithCarbonRector;
use Rector\Laravel\Rector\New_\AddGuardToLoginEventRector;
use Rector\Laravel\Rector\StaticCall\Redirect301ToPermanentRedirectRector;
use Rector\Removing\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Removing\ValueObject\ArgumentRemover;
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
use Rector\Visibility\ValueObject\ChangeMethodVisibility;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

View File

@ -3,13 +3,13 @@
declare(strict_types=1);
use Rector\Generic\Rector\FuncCall\SwapFuncCallArgumentsRector;
use Rector\Generic\ValueObject\RemoveFuncCallArg;
use Rector\Generic\ValueObject\SwapFuncCallArguments;
use Rector\MysqlToMysqli\Rector\Assign\MysqlAssignToMysqliRector;
use Rector\MysqlToMysqli\Rector\FuncCall\MysqlFuncCallToMysqliRector;
use Rector\MysqlToMysqli\Rector\FuncCall\MysqlPConnectToMysqliConnectRector;
use Rector\MysqlToMysqli\Rector\FuncCall\MysqlQueryMysqlErrorWithLinkRector;
use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector;
use Rector\Removing\ValueObject\RemoveFuncCallArg;
use Rector\Renaming\Rector\ConstFetch\RenameConstantRector;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

View File

@ -11,6 +11,7 @@ use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\UnionType;
use Rector\Core\ValueObject\MethodName;
use Rector\Nette\Rector\ClassMethod\TranslateClassMethodToVariadicsRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
@ -82,7 +83,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
),
new AddParamTypeDeclaration(
'Nette\Bridges\SecurityDI\SecurityExtension',
'__construct',
MethodName::CONSTRUCT,
0,
new BooleanType()
),
@ -94,7 +95,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
new UnionType([new ObjectType('Nette\Security\IIdentity'), new NullType()])
),
new AddParamTypeDeclaration('Nette\Security\IUserStorage', 'setExpiration', 1, new IntegerType()),
new AddParamTypeDeclaration('Nette\Security\Identity', '__construct', 2, $iterableType),
new AddParamTypeDeclaration('Nette\Security\Identity', MethodName::CONSTRUCT, 2, $iterableType),
new AddParamTypeDeclaration('Nette\Security\Identity', '__set', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Identity', '&__get', 0, new StringType()),
new AddParamTypeDeclaration('Nette\Security\Identity', '__isset', 0, new StringType()),

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Generic\Rector\ClassMethod\ArgumentDefaultValueReplacerRector;
use Rector\Generic\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector;
use Rector\Generic\ValueObject\ArgumentDefaultValueReplacer;
use Rector\Nette\Rector\Class_\MoveFinalGetUserToCheckRequirementsClassMethodRector;
use Rector\Nette\Rector\ClassMethod\RemoveParentAndNameFromComponentConstructorRector;
@ -21,6 +20,7 @@ use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Transform\Rector\StaticCall\StaticCallToMethodCallRector;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
use Rector\TypeDeclaration\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -8,7 +8,6 @@ use PHPStan\Type\UnionType;
use Rector\Composer\Rector\ChangePackageVersionComposerRector;
use Rector\Composer\Rector\RemovePackageComposerRector;
use Rector\Composer\ValueObject\PackageAndVersion;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Rector\Nette\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
@ -16,6 +15,7 @@ use Rector\Renaming\Rector\StaticCall\RenameStaticMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Renaming\ValueObject\RenameStaticMethod;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Transform\ValueObject\DimFetchAssignToMethodCall;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

View File

@ -2,10 +2,10 @@
declare(strict_types=1);
use Rector\Generic\ValueObject\RemoveFuncCallArg;
use Rector\Php52\Rector\Property\VarToPublicPropertyRector;
use Rector\Php52\Rector\Switch_\ContinueToBreakInSwitchRector;
use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector;
use Rector\Removing\ValueObject\RemoveFuncCallArg;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
use PHPStan\Type\MixedType;
use PHPStan\Type\VoidType;
use Rector\Core\ValueObject\MethodName;
use Rector\PHPUnit\Rector\MethodCall\AssertEqualsParameterToSpecificMethodsTypeRector;
use Rector\PHPUnit\Rector\MethodCall\ReplaceAssertArraySubsetWithDmsPolyfillRector;
use Rector\PHPUnit\Rector\MethodCall\SpecificAssertContainsRector;
@ -25,7 +26,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
->call('configure', [[
AddParamTypeDeclarationRector::PARAMETER_TYPEHINTS => ValueObjectInliner::inline([
// https://github.com/rectorphp/rector/issues/1024 - no type, $dataName
new AddParamTypeDeclaration('PHPUnit\Framework\TestCase', '__construct', 2, new MixedType()),
new AddParamTypeDeclaration('PHPUnit\Framework\TestCase', MethodName::CONSTRUCT, 2, new MixedType()),
]),
]]);

View File

@ -2,8 +2,8 @@
declare(strict_types=1);
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Removing\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Removing\ValueObject\ArgumentRemover;
use Rector\Symfony3\Rector\ClassMethod\MergeMethodAnnotationToRouteAnnotationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use Rector\Core\ValueObject\MethodName;
use Rector\Core\ValueObject\Visibility;
use Rector\Generic\NodeAnalyzer\ArgumentAddingScope;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
@ -12,9 +13,9 @@ use Rector\Generic\Rector\ClassMethod\ArgumentDefaultValueReplacerRector;
use Rector\Generic\Rector\ClassMethod\WrapReturnRector;
use Rector\Generic\ValueObject\ArgumentAdder;
use Rector\Generic\ValueObject\ArgumentDefaultValueReplacer;
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Generic\ValueObject\WrapReturn;
use Rector\Removing\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Removing\ValueObject\ArgumentRemover;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
@ -202,14 +203,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {
ArgumentDefaultValueReplacerRector::REPLACED_ARGUMENTS => ValueObjectInliner::inline([
new ArgumentDefaultValueReplacer(
'Symfony\Component\HttpFoundation\Cookie',
'__construct',
MethodName::CONSTRUCT,
5,
false,
null
),
new ArgumentDefaultValueReplacer(
'Symfony\Component\HttpFoundation\Cookie',
'__construct',
MethodName::CONSTRUCT,
8,
null,
'lax'
@ -223,13 +224,13 @@ return static function (ContainerConfigurator $containerConfigurator): void {
ArgumentRemoverRector::REMOVED_ARGUMENTS => ValueObjectInliner::inline([
new ArgumentRemover(
'Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector',
'__construct',
MethodName::CONSTRUCT,
0,
null
),
new ArgumentRemover(
'Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector',
'__construct',
MethodName::CONSTRUCT,
1,
null
),

View File

@ -2,6 +2,7 @@
declare(strict_types=1);
use Rector\Core\ValueObject\MethodName;
use Rector\Generic\Rector\ClassMethod\AddMethodParentCallRector;
use Rector\Generic\Rector\ClassMethod\ArgumentAdderRector;
@ -96,7 +97,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(AddMethodParentCallRector::class)
->call('configure', [[
AddMethodParentCallRector::METHODS_BY_PARENT_TYPES => [
'Symfony\Component\EventDispatcher\EventDispatcher' => '__construct',
'Symfony\Component\EventDispatcher\EventDispatcher' => MethodName::CONSTRUCT,
],
]]);
};

View File

@ -6853,7 +6853,7 @@ Removes defined arguments in defined methods and their calls.
```php
use Rector\Removing\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Removing\ValueObject\ArgumentRemover;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -7067,7 +7067,7 @@ Change magic array access add to `$list,` to explicit `$list->$addMethod(...)`
```php
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Rector\Transform\ValueObject\DimFetchAssignToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
@ -7107,7 +7107,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
Change null in argument, that is now not nullable anymore
- class: `Rector\Generic\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector`
- class: `Rector\TypeDeclaration\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector`
```diff
final class SomeClass
@ -7527,7 +7527,7 @@ Remove argument by position by function name
```php
use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector;
use Rector\Generic\ValueObject\RemoveFuncCallArg;
use Rector\Removing\ValueObject\RemoveFuncCallArg;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

View File

@ -136,7 +136,8 @@ final class RectorsFinder
}
if (! class_exists($class)) {
throw new ShouldNotHappenException($class);
$message = sprintf('Class "%s" was not found', $class);
throw new ShouldNotHappenException($message);
}
$reflectionClass = new ReflectionClass($class);

View File

@ -25,7 +25,7 @@ final class MergeInterfacesRector extends AbstractRector implements Configurable
* @api
* @var string
*/
public const OLD_TO_NEW_INTERFACES = '$oldToNewInterfaces';
public const OLD_TO_NEW_INTERFACES = 'old_to_new_interfaces';
/**
* @var string[]

View File

@ -1,111 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Rector\FuncCall;
use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Comments\CommentableNodeResolver;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeRemoval\BreakingRemovalGuard;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @sponsor Thanks https://twitter.com/afilina & Zenika (CAN) for sponsoring this rule - visit them on https://zenika.ca/en/en
*
* @see \Rector\Generic\Tests\Rector\FuncCall\RemoveIniGetSetFuncCallRector\RemoveIniGetSetFuncCallRectorTest
*/
final class RemoveIniGetSetFuncCallRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const KEYS_TO_REMOVE = '$keysToRemove';
/**
* @var string[]
*/
private $keysToRemove = [];
/**
* @var BreakingRemovalGuard
*/
private $breakingRemovalGuard;
/**
* @var CommentableNodeResolver
*/
private $commentableNodeResolver;
public function __construct(
BreakingRemovalGuard $breakingRemovalGuard,
CommentableNodeResolver $commentableNodeResolver
) {
$this->breakingRemovalGuard = $breakingRemovalGuard;
$this->commentableNodeResolver = $commentableNodeResolver;
}
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Remove ini_get by configuration', [
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
ini_get('y2k_compliance');
ini_set('y2k_compliance', 1);
CODE_SAMPLE
,
'',
[
self::KEYS_TO_REMOVE => ['y2k_compliance'],
]
), ]
);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node): ?Node
{
if (! $this->isNames($node, ['ini_get', 'ini_set'])) {
return null;
}
if (! isset($node->args[0])) {
return null;
}
$keyValue = $this->getValue($node->args[0]->value);
if (! in_array($keyValue, $this->keysToRemove, true)) {
return null;
}
if ($this->breakingRemovalGuard->isLegalNodeRemoval($node)) {
$this->removeNode($node);
} else {
$commentableNode = $this->commentableNodeResolver->resolve($node);
$commentableNode->setAttribute(AttributeKey::COMMENTS, [new Comment('// @fixme')]);
}
return null;
}
public function configure(array $configuration): void
{
$this->keysToRemove = $configuration[self::KEYS_TO_REMOVE] ?? [];
}
}

View File

@ -1,51 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
final class SwapClassMethodArguments
{
/**
* @var string
*/
private $class;
/**
* @var string
*/
private $method;
/**
* @var array<int, int>
*/
private $order = [];
/**
* @param array<int, int> $order
*/
public function __construct(string $class, string $method, array $order)
{
$this->class = $class;
$this->method = $method;
$this->order = $order;
}
public function getClass(): string
{
return $this->class;
}
public function getMethod(): string
{
return $this->method;
}
/**
* @return array<int, int>
*/
public function getOrder(): array
{
return $this->order;
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\NowString;
final class SomeClass
{
public function run(NowString $nowString)
{
$nowString->setValue(null);
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\NowString;
final class SomeClass
{
public function run(NowString $nowString)
{
$nowString->setValue('');
}
}
?>

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\NowBool;
final class FormerBool
{
public function run(NowBool $nowBool)
{
$nowBool->setValue(null);
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\NowBool;
final class FormerBool
{
public function run(NowBool $nowBool)
{
$nowBool->setValue(false);
}
}
?>

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\StaticNowInteger;
final class OnStaticCall
{
public function run()
{
StaticNowInteger::setValue(null);
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\StaticNowInteger;
final class OnStaticCall
{
public function run()
{
StaticNowInteger::setValue(0);
}
}
?>

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\ParentMethodFormerInteger;
final class WithParentMethod
{
public function run(ParentMethodFormerInteger $parentMethodFormerInteger)
{
$parentMethodFormerInteger->setValue(null);
}
}
?>
-----
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\ParentMethodFormerInteger;
final class WithParentMethod
{
public function run(ParentMethodFormerInteger $parentMethodFormerInteger)
{
$parentMethodFormerInteger->setValue(0);
}
}
?>

View File

@ -1,9 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source;
final class ParentMethodFormerInteger extends StaticNowInteger
{
}

View File

@ -11,7 +11,7 @@ use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Removing\ValueObject\ArgumentRemover;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

View File

@ -8,7 +8,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\RemoveFuncCallArg;
use Rector\Removing\ValueObject\RemoveFuncCallArg;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

View File

@ -0,0 +1,147 @@
<?php
declare(strict_types=1);
namespace Rector\Removing\Rector\FuncCall;
use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use Rector\Core\Comments\CommentableNodeResolver;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeRemoval\BreakingRemovalGuard;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Removing\ValueObject\RemoveFuncCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @sponsor Thanks https://twitter.com/afilina & Zenika (CAN) for sponsoring this rule - visit them on https://zenika.ca/en/en
*
* @see \Rector\Removing\Tests\Rector\FuncCall\RemoveFuncCallRector\RemoveFuncCallRectorTest
*/
final class RemoveFuncCallRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const REMOVE_FUNC_CALLS = 'remove_func_calls';
/**
* @var RemoveFuncCall[]
*/
private $removeFuncCalls = [];
/**
* @var BreakingRemovalGuard
*/
private $breakingRemovalGuard;
/**
* @var CommentableNodeResolver
*/
private $commentableNodeResolver;
public function __construct(
BreakingRemovalGuard $breakingRemovalGuard,
CommentableNodeResolver $commentableNodeResolver
) {
$this->breakingRemovalGuard = $breakingRemovalGuard;
$this->commentableNodeResolver = $commentableNodeResolver;
}
public function getRuleDefinition(): RuleDefinition
{
$configuration = [
self::REMOVE_FUNC_CALLS => [
new RemoveFuncCall('ini_get', [
1 => ['y2k_compliance'],
]),
],
];
return new RuleDefinition('Remove ini_get by configuration', [
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
ini_get('y2k_compliance');
ini_get('keep_me');
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
ini_get('keep_me');
CODE_SAMPLE
,
$configuration
), ]
);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node): ?Node
{
foreach ($this->removeFuncCalls as $removeFuncCall) {
if (! $this->isName($node, $removeFuncCall->getFuncCall())) {
continue;
}
if ($removeFuncCall->getArgumentPositionAndValues() === []) {
$this->removeNode($node);
return null;
}
$this->refactorFuncCallsWithPositions($node, $removeFuncCall);
}
return null;
}
/**
* @param array<string, RemoveFuncCall[]> $configuration
*/
public function configure(array $configuration): void
{
$removeFuncCalls = $configuration[self::REMOVE_FUNC_CALLS] ?? [];
Assert::allIsInstanceOf($removeFuncCalls, RemoveFuncCall::class);
$this->removeFuncCalls = $removeFuncCalls;
}
private function refactorFuncCallsWithPositions(FuncCall $funcCall, RemoveFuncCall $removeFuncCall): void
{
foreach ($removeFuncCall->getArgumentPositionAndValues() as $argumentPosition => $values) {
if (! $this->isArgumentPositionValueMatch($funcCall, $argumentPosition, $values)) {
continue;
}
if ($this->breakingRemovalGuard->isLegalNodeRemoval($funcCall)) {
$this->removeNode($funcCall);
} else {
$commentableNode = $this->commentableNodeResolver->resolve($funcCall);
$commentableNode->setAttribute(AttributeKey::COMMENTS, [new Comment('// @fixme')]);
}
}
}
/**
* @param mixed[] $values
*/
private function isArgumentPositionValueMatch(FuncCall $funcCall, int $argumentPosition, array $values): bool
{
if (! isset($funcCall->args[$argumentPosition])) {
return false;
}
return $this->isValues($funcCall->args[$argumentPosition]->value, $values);
}
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
namespace Rector\Removing\ValueObject;
final class ArgumentRemover
{

View File

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Rector\Removing\ValueObject;
final class RemoveFuncCall
{
/**
* @var string
*/
private $funcCall;
/**
* @var array<int, mixed[]>
*/
private $argumentPositionAndValues = [];
/**
* @param array<int, mixed[]> $argumentPositionAndValues
*/
public function __construct(string $funcCall, array $argumentPositionAndValues = [])
{
$this->funcCall = $funcCall;
$this->argumentPositionAndValues = $argumentPositionAndValues;
}
public function getFuncCall(): string
{
return $this->funcCall;
}
/**
* @return array<int, mixed[]>
*/
public function getArgumentPositionAndValues(): array
{
return $this->argumentPositionAndValues;
}
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\ValueObject;
namespace Rector\Removing\ValueObject;
final class RemoveFuncCallArg
{

View File

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace Rector\Removing\Tests\Rector\ClassMethod\ArgumentRemoverRector;
use Iterator;
use Rector\Generic\ValueObject\ArgumentRemover;
use Rector\Removing\Rector\ClassMethod\ArgumentRemoverRector;
use Rector\Removing\Tests\Rector\ClassMethod\ArgumentRemoverRector\Source\Persister;
use Rector\Removing\Tests\Rector\ClassMethod\ArgumentRemoverRector\Source\RemoveInTheMiddle;
use Rector\Removing\ValueObject\ArgumentRemover;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symfony\Component\Yaml\Yaml;
use Symplify\SmartFileSystem\SmartFileInfo;

View File

@ -5,8 +5,8 @@ declare(strict_types=1);
namespace Rector\Removing\Tests\Rector\FuncCall\RemoveFuncCallArgRector;
use Iterator;
use Rector\Generic\ValueObject\RemoveFuncCallArg;
use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector;
use Rector\Removing\ValueObject\RemoveFuncCallArg;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use SplFileInfo;
use Symplify\SmartFileSystem\SmartFileInfo;

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\RemoveIniGetSetFuncCallRector\Fixture;
namespace Rector\Removing\Tests\Rector\FuncCall\RemoveFuncCallRector\Fixture;
class GetAssign
{
@ -16,7 +16,7 @@ class GetAssign
-----
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\RemoveIniGetSetFuncCallRector\Fixture;
namespace Rector\Removing\Tests\Rector\FuncCall\RemoveFuncCallRector\Fixture;
class GetAssign
{

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\RemoveIniGetSetFuncCallRector\Fixture;
namespace Rector\Removing\Tests\Rector\FuncCall\RemoveFuncCallRector\Fixture;
ini_get('bla');
ini_set('y2kcompliance', 0);

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\RemoveIniGetSetFuncCallRector\Fixture;
namespace Rector\Removing\Tests\Rector\FuncCall\RemoveFuncCallRector\Fixture;
$aRandomVar = false;
@ -13,7 +13,7 @@ ini_set('safe_mode', $aRandomVar);
-----
<?php
namespace Rector\Generic\Tests\Rector\FuncCall\RemoveIniGetSetFuncCallRector\Fixture;
namespace Rector\Removing\Tests\Rector\FuncCall\RemoveFuncCallRector\Fixture;
$aRandomVar = false;

View File

@ -2,15 +2,16 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\FuncCall\RemoveIniGetSetFuncCallRector;
namespace Rector\Removing\Tests\Rector\FuncCall\RemoveFuncCallRector;
use Iterator;
use Rector\Generic\Rector\FuncCall\RemoveIniGetSetFuncCallRector;
use Rector\Removing\Rector\FuncCall\RemoveFuncCallRector;
use Rector\Removing\ValueObject\RemoveFuncCall;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use SplFileInfo;
use Symplify\SmartFileSystem\SmartFileInfo;
final class RemoveIniGetSetFuncCallRectorTest extends AbstractRectorTestCase
final class RemoveFuncCallRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
@ -34,11 +35,14 @@ final class RemoveIniGetSetFuncCallRectorTest extends AbstractRectorTestCase
protected function getRectorsWithConfiguration(): array
{
return [
RemoveIniGetSetFuncCallRector::class => [
RemoveIniGetSetFuncCallRector::KEYS_TO_REMOVE => [
'y2k_compliance',
'safe_mode',
'magic_quotes_runtime',
RemoveFuncCallRector::class => [
RemoveFuncCallRector::REMOVE_FUNC_CALLS => [
new RemoveFuncCall('ini_get', [
0 => ['y2k_compliance', 'safe_mode', 'magic_quotes_runtime'],
]),
new RemoveFuncCall('ini_set', [
0 => ['y2k_compliance', 'safe_mode', 'magic_quotes_runtime'],
]),
],
],
];

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\NodeTypeAnalyzer;
namespace Rector\Transform\NodeTypeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector;
namespace Rector\Transform\Rector;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
@ -14,10 +14,10 @@ use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\NodeTypeAnalyzer\TypeProvidingExprFromClassResolver;
use Rector\Naming\Naming\PropertyNaming;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Rector\Transform\NodeFactory\PropertyFetchFactory;
use Rector\Transform\NodeTypeAnalyzer\TypeProvidingExprFromClassResolver;
abstract class AbstractToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface
{

View File

@ -12,7 +12,7 @@ use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Variable;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Rector\Transform\ValueObject\DimFetchAssignToMethodCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

View File

@ -8,8 +8,8 @@ use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Generic\Rector\AbstractToMethodCallRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Transform\Rector\AbstractToMethodCallRector;
use Rector\Transform\ValueObject\FuncNameToMethodCallName;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

View File

@ -12,8 +12,8 @@ use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Generic\Rector\AbstractToMethodCallRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Transform\Rector\AbstractToMethodCallRector;
use Rector\Transform\ValueObject\StaticCallToMethodCall;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1);
namespace Rector\Generic\ValueObject;
namespace Rector\Transform\ValueObject;
final class DimFetchAssignToMethodCall
{

View File

@ -5,9 +5,9 @@ declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\Assign\DimFetchAssignToMethodCallRector;
use Iterator;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Transform\ValueObject\DimFetchAssignToMethodCall;
use Symplify\SmartFileSystem\SmartFileInfo;
final class DimFetchAssignToMethodCallRectorTest extends AbstractRectorTestCase

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Rector\Transform\Tests\Rector\FuncCall\FuncCallToMethodCallRector\Source;
if (function_exists('Rector\Generic\Tests\Rector\FuncCall\FuncCallToMethodCallRector\Source\some_view_function')) {
if (function_exists('Rector\Removing\Tests\Rector\FuncCall\FuncCallToMethodCallRector\Source\some_view_function')) {
return;
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\NodeTypeAnalyzer;
namespace Rector\TypeDeclaration\NodeTypeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Rector\MethodCall;
namespace Rector\TypeDeclaration\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
@ -17,14 +17,14 @@ use PHPStan\Type\IntegerType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use Rector\Core\Rector\AbstractRector;
use Rector\Generic\NodeTypeAnalyzer\CallTypeAnalyzer;
use Rector\TypeDeclaration\NodeTypeAnalyzer\CallTypeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @sponsor Thanks https://amateri.com for sponsoring this rule - visit them on https://www.startupjobs.cz/startup/scrumworks-s-r-o
*
* @see \Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\FormerNullableArgumentToScalarTypedRectorTest
* @see \Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\FormerNullableArgumentToScalarTypedRectorTest
*/
final class FormerNullableArgumentToScalarTypedRector extends AbstractRector
{

View File

@ -3,7 +3,7 @@
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Rector\Transform\ValueObject\DimFetchAssignToMethodCall;
final class ConfigurationWithStringStringArray
{
@ -30,12 +30,12 @@ final class ConfigurationWithStringStringArray
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
use Rector\Transform\Rector\Assign\DimFetchAssignToMethodCallRector;
use Rector\Generic\ValueObject\DimFetchAssignToMethodCall;
use Rector\Transform\ValueObject\DimFetchAssignToMethodCall;
final class ConfigurationWithStringStringArray
{
/**
* @return array<string, array<string, \Rector\Generic\ValueObject\DimFetchAssignToMethodCall[]>>
* @return array<string, array<string, \Rector\Transform\ValueObject\DimFetchAssignToMethodCall[]>>
*/
public function getSome(): array
{

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\NowString;
final class SomeClass
{
public function run(NowString $nowString)
{
$nowString->setValue(null);
}
}
?>
-----
<?php
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\NowString;
final class SomeClass
{
public function run(NowString $nowString)
{
$nowString->setValue('');
}
}
?>

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\NowBool;
final class FormerBool
{
public function run(NowBool $nowBool)
{
$nowBool->setValue(null);
}
}
?>
-----
<?php
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\NowBool;
final class FormerBool
{
public function run(NowBool $nowBool)
{
$nowBool->setValue(false);
}
}
?>

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\StaticNowInteger;
final class OnStaticCall
{
public function run()
{
StaticNowInteger::setValue(null);
}
}
?>
-----
<?php
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\StaticNowInteger;
final class OnStaticCall
{
public function run()
{
StaticNowInteger::setValue(0);
}
}
?>

View File

@ -1,6 +1,6 @@
<?php
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Nette\Application\UI\Form;

View File

@ -0,0 +1,31 @@
<?php
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\ParentMethodFormerInteger;
final class WithParentMethod
{
public function run(ParentMethodFormerInteger $parentMethodFormerInteger)
{
$parentMethodFormerInteger->setValue(null);
}
}
?>
-----
<?php
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source\ParentMethodFormerInteger;
final class WithParentMethod
{
public function run(ParentMethodFormerInteger $parentMethodFormerInteger)
{
$parentMethodFormerInteger->setValue(0);
}
}
?>

View File

@ -2,11 +2,11 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector;
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector;
use Iterator;
use Rector\Generic\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\TypeDeclaration\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector;
use Symplify\SmartFileSystem\SmartFileInfo;
final class FormerNullableArgumentToScalarTypedRectorTest extends AbstractRectorTestCase

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source;
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source;
final class NowBool
{

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source;
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source;
final class NowString
{

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source;
final class ParentMethodFormerInteger extends StaticNowInteger
{
}

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source;
namespace Rector\TypeDeclaration\Tests\Rector\MethodCall\FormerNullableArgumentToScalarTypedRector\Source;
class StaticNowInteger
{