[DX] Add strict PHPStan rules - step #2 (#1330)

This commit is contained in:
Tomas Votruba 2021-11-28 19:45:10 +03:00 committed by GitHub
parent f985e811be
commit 39a530c1f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
115 changed files with 317 additions and 276 deletions

View File

@ -583,3 +583,10 @@ parameters:
# skip === false compare
- '#Do not compare call directly, use a variable assign#'
# strict - resolve later
- '#Foreach overwrites \$(.*?) with its value variable#'
-
message: '#Strict comparison using \!\=\= between null and null will always evaluate to false#'
path: rules/Renaming/Rector/FileWithoutNamespace/PseudoNamespaceToNamespaceRector.php

View File

@ -8,9 +8,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(FuncCallToNewRector::class)
->call('configure', [[
FuncCallToNewRector::FUNCTIONS_TO_NEWS => [
'collection' => ['Collection'],
],
]]);
->configure([
'collection' => 'Collection',
]);
};

View File

@ -130,12 +130,12 @@ CODE_SAMPLE
}
/**
* @param array<string, ArgumentAdder[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$addedArguments = $configuration[self::ADDED_ARGUMENTS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($addedArguments, ArgumentAdder::class);
$addedArguments = $configuration[self::ADDED_ARGUMENTS] ?? $configuration;
Assert::allIsAOf($addedArguments, ArgumentAdder::class);
$this->addedArguments = $addedArguments;
}

View File

@ -100,12 +100,12 @@ CODE_SAMPLE
}
/**
* @param array<string, ReplaceArgumentDefaultValue[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$replacedArguments = $configuration[self::REPLACED_ARGUMENTS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($replacedArguments, ReplaceArgumentDefaultValue::class);
$replacedArguments = $configuration[self::REPLACED_ARGUMENTS] ?? $configuration;
Assert::allIsAOf($replacedArguments, ReplaceArgumentDefaultValue::class);
$this->replacedArguments = $replacedArguments;
}
}

View File

@ -84,12 +84,12 @@ CODE_SAMPLE
}
/**
* @param array<string, ReplaceFuncCallArgumentDefaultValue[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$replacedArguments = $configuration[self::REPLACED_ARGUMENTS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($replacedArguments, ReplaceFuncCallArgumentDefaultValue::class);
$replacedArguments = $configuration[self::REPLACED_ARGUMENTS] ?? $configuration;
Assert::allIsAOf($replacedArguments, ReplaceFuncCallArgumentDefaultValue::class);
$this->replacedArguments = $replacedArguments;
}
}

View File

@ -106,12 +106,12 @@ CODE_SAMPLE
}
/**
* @param array<string, SwapFuncCallArguments[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$functionArgumentSwaps = $configuration[self::FUNCTION_ARGUMENT_SWAPS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($functionArgumentSwaps, SwapFuncCallArguments::class);
$functionArgumentSwaps = $configuration[self::FUNCTION_ARGUMENT_SWAPS] ?? $configuration;
Assert::allIsAOf($functionArgumentSwaps, SwapFuncCallArguments::class);
$this->functionArgumentSwaps = $functionArgumentSwaps;
}

View File

@ -91,11 +91,12 @@ CODE_SAMPLE
}
/**
* @param array<string, string[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$groupNamesBySuffix = $configuration[self::GROUP_NAMES_BY_SUFFIX] ?? ($configuration ?: []);
$groupNamesBySuffix = $configuration[self::GROUP_NAMES_BY_SUFFIX] ?? $configuration;
Assert::isArray($groupNamesBySuffix);
Assert::allString($groupNamesBySuffix);
$this->groupNamesBySuffix = $groupNamesBySuffix;

View File

@ -151,7 +151,7 @@ CODE_SAMPLE
}
/**
* @param array<string, mixed> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{

View File

@ -108,11 +108,11 @@ CODE_SAMPLE
}
/**
* @param array<string, mixed> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$attributesOrder = $configuration[self::ATTRIBUTES_ORDER] ?? ($configuration ?: []);
$attributesOrder = $configuration[self::ATTRIBUTES_ORDER] ?? $configuration;
Assert::isArray($attributesOrder);
Assert::allString($attributesOrder);

View File

@ -124,12 +124,12 @@ CODE_SAMPLE
}
/**
* @param array<string, ReturnArrayClassMethodToYield[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$methodsToYields = $configuration[self::METHODS_TO_YIELDS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($methodsToYields, ReturnArrayClassMethodToYield::class);
$methodsToYields = $configuration[self::METHODS_TO_YIELDS] ?? $configuration;
Assert::allIsAOf($methodsToYields, ReturnArrayClassMethodToYield::class);
$this->methodsToYields = $methodsToYields;
}

View File

@ -106,7 +106,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$typeToPreference = $configuration[self::TYPE_TO_PREFERENCE] ?? ($configuration ?: []);
$typeToPreference = $configuration[self::TYPE_TO_PREFERENCE] ?? $configuration;
Assert::allIsAOf($typeToPreference, PreferenceSelfThis::class);
$this->typeToPreference = $typeToPreference;

View File

@ -63,12 +63,12 @@ CODE_SAMPLE
}
/**
* @param array<string, PackageAndVersion[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$packagesAndVersions = $configuration[self::PACKAGES_AND_VERSIONS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($packagesAndVersions, PackageAndVersion::class);
$packagesAndVersions = $configuration[self::PACKAGES_AND_VERSIONS] ?? $configuration;
Assert::allIsAOf($packagesAndVersions, PackageAndVersion::class);
$this->versionGuard->validate($packagesAndVersions);
$this->packagesAndVersions = $packagesAndVersions;

View File

@ -66,12 +66,12 @@ CODE_SAMPLE
}
/**
* @param array<string, PackageAndVersion[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$packagesAndVersions = $configuration[self::PACKAGES_AND_VERSIONS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($packagesAndVersions, PackageAndVersion::class);
$packagesAndVersions = $configuration[self::PACKAGES_AND_VERSIONS] ?? $configuration;
Assert::allIsAOf($packagesAndVersions, PackageAndVersion::class);
$this->versionGuard->validate($packagesAndVersions);
$this->packageAndVersions = $packagesAndVersions;

View File

@ -69,12 +69,12 @@ CODE_SAMPLE
}
/**
* @param array<string, PackageAndVersion[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$packagesAndVersions = $configuration[self::PACKAGES_AND_VERSIONS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($packagesAndVersions, PackageAndVersion::class);
$packagesAndVersions = $configuration[self::PACKAGES_AND_VERSIONS] ?? $configuration;
Assert::allIsAOf($packagesAndVersions, PackageAndVersion::class);
$this->versionGuard->validate($packagesAndVersions);
$this->packagesAndVersions = $packagesAndVersions;

View File

@ -60,7 +60,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$packagesNames = $configuration[self::PACKAGE_NAMES] ?? ($configuration ?: []);
$packagesNames = $configuration[self::PACKAGE_NAMES] ?? $configuration;
Assert::isArray($packagesNames);
Assert::allString($packagesNames);

View File

@ -76,12 +76,12 @@ CODE_SAMPLE
}
/**
* @param array<string, RenamePackage[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$renamePackages = $configuration[self::RENAME_PACKAGES] ?? ($configuration ?: []);
Assert::allIsInstanceOf($renamePackages, RenamePackage::class);
$renamePackages = $configuration[self::RENAME_PACKAGES] ?? $configuration;
Assert::allIsAOf($renamePackages, RenamePackage::class);
$this->renamePackages = $renamePackages;
}
}

View File

@ -74,12 +74,12 @@ CODE_SAMPLE
}
/**
* @param array<string, ReplacePackageAndVersion[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$replacePackagesAndVersions = $configuration[self::REPLACE_PACKAGES_AND_VERSIONS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($replacePackagesAndVersions, ReplacePackageAndVersion::class);
$replacePackagesAndVersions = $configuration[self::REPLACE_PACKAGES_AND_VERSIONS] ?? $configuration;
Assert::allIsAOf($replacePackagesAndVersions, ReplacePackageAndVersion::class);
$this->versionGuard->validate($replacePackagesAndVersions);
$this->replacePackagesAndVersions = $replacePackagesAndVersions;

View File

@ -101,11 +101,12 @@ CODE_SAMPLE
}
/**
* @param array<string, string[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$annotationsToRemove = $configuration[self::ANNOTATIONS_TO_REMOVE] ?? ($configuration ?: []);
$annotationsToRemove = $configuration[self::ANNOTATIONS_TO_REMOVE] ?? $configuration;
Assert::isArray($annotationsToRemove);
Assert::allString($annotationsToRemove);
$this->annotationsToRemove = $annotationsToRemove;

View File

@ -38,7 +38,7 @@ final class RemovePhpVersionIdCheckRector extends AbstractRector implements Conf
}
/**
* @param array<string, int|string> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{

View File

@ -118,7 +118,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$methodsByParentTypes = $configuration[self::METHODS_BY_PARENT_TYPES] ?? ($configuration ?: []);
$methodsByParentTypes = $configuration[self::METHODS_BY_PARENT_TYPES] ?? $configuration;
Assert::allString(array_keys($methodsByParentTypes));
Assert::allString($methodsByParentTypes);

View File

@ -139,16 +139,16 @@ CODE_SAMPLE
}
/**
* @param array<string, mixed> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$safeTypes = $configuration[self::SAFE_TYPES] ?? ($configuration ?: []);
$safeTypes = $configuration[self::SAFE_TYPES] ?? $configuration;
Assert::isArray($safeTypes);
Assert::allString($safeTypes);
$this->safeTypes = $safeTypes;
$safeTypesToMethods = $configuration[self::SAFE_TYPES_TO_METHODS] ?? ($configuration ?: []);
$safeTypesToMethods = $configuration[self::SAFE_TYPES_TO_METHODS] ?? $configuration;
Assert::isArray($safeTypesToMethods);
foreach ($safeTypesToMethods as $key => $value) {
Assert::string($key);

View File

@ -128,12 +128,12 @@ CODE_SAMPLE
}
/**
* @param array<string, DowngradeAttributeToAnnotation[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$attributesToAnnotations = $configuration[self::ATTRIBUTE_TO_ANNOTATION] ?? ($configuration ?: []);
Assert::allIsInstanceOf($attributesToAnnotations, DowngradeAttributeToAnnotation::class);
$attributesToAnnotations = $configuration[self::ATTRIBUTE_TO_ANNOTATION] ?? $configuration;
Assert::allIsAOf($attributesToAnnotations, DowngradeAttributeToAnnotation::class);
$this->attributesToAnnotations = $attributesToAnnotations;
}

View File

@ -127,7 +127,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$makeClassMethodGenerics = $configuration[self::GENERIC_CLASS_METHOD_PARAMS] ?? ($configuration ?: []);
$makeClassMethodGenerics = $configuration[self::GENERIC_CLASS_METHOD_PARAMS] ?? $configuration;
Assert::allIsAOf($makeClassMethodGenerics, GenericClassMethodParam::class);
$this->genericClassMethodParams = $makeClassMethodGenerics;

View File

@ -6,7 +6,13 @@ namespace Rector\Naming\Contract\Guard;
use Rector\Naming\Contract\RenameValueObjectInterface;
/**
* @template TRename as RenameValueObjectInterface
*/
interface ConflictingNameGuardInterface
{
/**
* @param TRename $renameValueObject
*/
public function isConflicting(RenameValueObjectInterface $renameValueObject): bool;
}

View File

@ -13,6 +13,9 @@ use Rector\Naming\ValueObject\PropertyRename;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper;
/**
* @implements ConflictingNameGuardInterface<PropertyRename>
*/
final class DateTimeAtNamingConventionGuard implements ConflictingNameGuardInterface
{
/**

View File

@ -9,6 +9,9 @@ use Rector\Naming\Contract\Guard\ConflictingNameGuardInterface;
use Rector\Naming\Contract\RenameValueObjectInterface;
use Rector\Naming\ValueObject\PropertyRename;
/**
* @implements ConflictingNameGuardInterface<PropertyRename>
*/
final class HasMagicGetSetGuard implements ConflictingNameGuardInterface
{
public function __construct(

View File

@ -8,6 +8,9 @@ use Rector\Naming\Contract\Guard\ConflictingNameGuardInterface;
use Rector\Naming\Contract\RenameValueObjectInterface;
use Rector\Naming\ValueObject\PropertyRename;
/**
* @implements ConflictingNameGuardInterface<PropertyRename>
*/
final class NotPrivatePropertyGuard implements ConflictingNameGuardInterface
{
/**

View File

@ -10,6 +10,9 @@ use Rector\Naming\Contract\RenameValueObjectInterface;
use Rector\Naming\ValueObject\PropertyRename;
use Rector\NodeTypeResolver\NodeTypeResolver;
/**
* @implements ConflictingNameGuardInterface<PropertyRename>
*/
final class RamseyUuidInterfaceGuard implements ConflictingNameGuardInterface
{
public function __construct(

View File

@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Rector\Naming\PhpArray;
use Rector\Core\Exception\ShouldNotHappenException;
final class ArrayFilter
{
/**
@ -25,10 +23,6 @@ final class ArrayFilter
continue;
}
if (! is_string($value)) {
throw new ShouldNotHappenException();
}
$duplicatedValues[] = $value;
}

View File

@ -117,11 +117,13 @@ CODE_SAMPLE
}
/**
* @param array<string, string[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$classesToSkip = $configuration[self::CLASSES_TO_SKIP] ?? ($configuration ?: []);
$classesToSkip = $configuration[self::CLASSES_TO_SKIP] ?? $configuration;
Assert::isArray($classesToSkip);
Assert::allString($classesToSkip);
$this->classesToSkip = $classesToSkip;

View File

@ -8,7 +8,6 @@ use Nette\Utils\Strings;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
final class RegexMatcher
@ -40,9 +39,6 @@ final class RegexMatcher
}
$delimiter = $pattern[0];
if (! is_string($delimiter)) {
throw new ShouldNotHappenException();
}
/** @var string $modifiers */
$modifiers = Strings::after($pattern, $delimiter, -1);

View File

@ -93,7 +93,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$reservedKeywordsToReplacements = $configuration[self::RESERVED_KEYWORDS_TO_REPLACEMENTS] ?? ($configuration ?: []);
$reservedKeywordsToReplacements = $configuration[self::RESERVED_KEYWORDS_TO_REPLACEMENTS] ?? $configuration;
Assert::isArray($reservedKeywordsToReplacements);
Assert::allString(array_keys($reservedKeywordsToReplacements));

View File

@ -80,13 +80,13 @@ CODE_SAMPLE
$eachFuncCall = $node->expr;
// only key: list($key, ) = each($values);
if ($listNode->items[0] && $listNode->items[1] === null) {
if ($listNode->items[0] instanceof ArrayItem && $listNode->items[1] === null) {
$keyFuncCall = $this->nodeFactory->createFuncCall('key', $eachFuncCall->args);
return new Assign($listNode->items[0]->value, $keyFuncCall);
}
// only value: list(, $value) = each($values);
if ($listNode->items[1] && $listNode->items[0] === null) {
if ($listNode->items[1] instanceof ArrayItem && $listNode->items[0] === null) {
$nextFuncCall = $this->nodeFactory->createFuncCall('next', $eachFuncCall->args);
$this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $node);

View File

@ -117,7 +117,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$reservedNamesToNewOnes = $configuration[self::RESERVED_NAMES_TO_NEW_ONES] ?? ($configuration ?: []);
$reservedNamesToNewOnes = $configuration[self::RESERVED_NAMES_TO_NEW_ONES] ?? $configuration;
Assert::allString(array_keys($reservedNamesToNewOnes));
Assert::allString($reservedNamesToNewOnes);

View File

@ -48,7 +48,7 @@ final class AddLiteralSeparatorToNumberRector extends AbstractRector implements
private int $limitValue = self::DEFAULT_LIMIT_VALUE;
/**
* @param array<string, int> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{

View File

@ -188,7 +188,7 @@ CODE_SAMPLE
if ($methodCall->var instanceof Variable) {
$variableName = $this->getName($methodCall->var);
$methodName = $this->getName($methodCall->name);
if (! $variableName) {
if (! is_string($variableName)) {
return;
}

View File

@ -186,7 +186,7 @@ CODE_SAMPLE
}
/**
* @param array<string, bool> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{

View File

@ -5,14 +5,15 @@ declare(strict_types=1);
namespace Rector\Php80\Contract;
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\FuncCall;
use Rector\Php80\ValueObject\StrStartsWith;
interface StrStartWithMatchAndRefactorInterface
{
public function match(BinaryOp $binaryOp): ?StrStartsWith;
public function match(Identical|NotIdentical $binaryOp): ?StrStartsWith;
/**
* @return FuncCall|BooleanNot|null

View File

@ -6,7 +6,6 @@ namespace Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\FuncCall;
@ -36,10 +35,7 @@ final class StrncmpMatchAndRefactor implements StrStartWithMatchAndRefactorInter
) {
}
/**
* @param Identical|NotIdentical $binaryOp
*/
public function match(BinaryOp $binaryOp): ?StrStartsWith
public function match(Identical|NotIdentical $binaryOp): ?StrStartsWith
{
$isPositive = $binaryOp instanceof Identical;

View File

@ -29,10 +29,7 @@ final class StrposMatchAndRefactor implements StrStartWithMatchAndRefactorInterf
) {
}
/**
* @param Identical|NotIdentical $binaryOp
*/
public function match(BinaryOp $binaryOp): ?StrStartsWith
public function match(Identical|NotIdentical $binaryOp): ?StrStartsWith
{
$isPositive = $binaryOp instanceof Identical;

View File

@ -6,7 +6,6 @@ namespace Rector\Php80\MatchAndRefactor\StrStartsWithMatchAndRefactor;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\FuncCall;
@ -31,10 +30,7 @@ final class SubstrMatchAndRefactor implements StrStartWithMatchAndRefactorInterf
) {
}
/**
* @param Identical|NotIdentical $binaryOp
*/
public function match(BinaryOp $binaryOp): ?StrStartsWith
public function match(Identical|NotIdentical $binaryOp): ?StrStartsWith
{
$isPositive = $binaryOp instanceof Identical;

View File

@ -84,7 +84,7 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
$isAlreadySorted = $node->getAttribute(self::ALREADY_SORTED);
$isAlreadySorted = (bool) $node->getAttribute(self::ALREADY_SORTED, false);
if ($isAlreadySorted) {
return null;
}

View File

@ -140,12 +140,12 @@ CODE_SAMPLE
}
/**
* @param array<string, AnnotationToAttribute[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$annotationsToAttributes = $configuration[self::ANNOTATION_TO_ATTRIBUTE] ?? ($configuration ?: []);
Assert::allIsInstanceOf($annotationsToAttributes, AnnotationToAttribute::class);
$annotationsToAttributes = $configuration[self::ANNOTATION_TO_ATTRIBUTE] ?? $configuration;
Assert::allIsAOf($annotationsToAttributes, AnnotationToAttribute::class);
$this->annotationsToAttributes = $annotationsToAttributes;
}

View File

@ -164,7 +164,7 @@ CODE_SAMPLE
}
/**
* @param array<string, bool> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{

View File

@ -33,13 +33,13 @@ final class AssertMethodCallFactory
$this->isBoolAssert = false;
// special case with bool!
if ($expected !== null) {
if ($expected instanceof Expr) {
$name = $this->resolveBoolMethodName($name, $expected);
}
$assetMethodCall = $this->nodeFactory->createMethodCall('this', $name);
if (! $this->isBoolAssert && $expected) {
if (! $this->isBoolAssert && $expected instanceof Expr) {
$assetMethodCall->args[] = new Arg($this->thisToTestedObjectPropertyFetch(
$expected,
$testedObjectPropertyFetch

View File

@ -60,7 +60,7 @@ final class PhpSpecClassToPHPUnitClassRector extends AbstractPhpSpecToPHPUnitRec
return null;
}
$isAlreadyRenamedToTest = $node->getAttribute(self::ALREADY_RENAMED_TO_TEST);
$isAlreadyRenamedToTest = (bool) $node->getAttribute(self::ALREADY_RENAMED_TO_TEST, false);
if ($isAlreadyRenamedToTest) {
return null;
}

View File

@ -115,11 +115,11 @@ CODE_SAMPLE
}
/**
* @param array<string, mixed[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$this->replaceStringWithClassConstants = $configuration[self::REPLACE_STRING_WITH_CLASS_CONSTANT] ?? ($configuration ?: []);
$this->replaceStringWithClassConstants = $configuration[self::REPLACE_STRING_WITH_CLASS_CONSTANT] ?? $configuration;
}
private function matchArg(

View File

@ -88,12 +88,12 @@ CODE_SAMPLE
}
/**
* @param array<string, ArgumentRemover[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$removedArguments = $configuration[self::REMOVED_ARGUMENTS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($removedArguments, ArgumentRemover::class);
$removedArguments = $configuration[self::REMOVED_ARGUMENTS] ?? $configuration;
Assert::allIsAOf($removedArguments, ArgumentRemover::class);
$this->removedArguments = $removedArguments;
}

View File

@ -81,7 +81,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$interfacesToRemove = $configuration[self::INTERFACES_TO_REMOVE] ?? ($configuration ?: []);
$interfacesToRemove = $configuration[self::INTERFACES_TO_REMOVE] ?? $configuration;
Assert::allString($interfacesToRemove);
/** @var string[] $interfacesToRemove */

View File

@ -98,7 +98,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$parentTypesToRemove = $configuration[self::PARENT_TYPES_TO_REMOVE] ?? ($configuration ?: []);
$parentTypesToRemove = $configuration[self::PARENT_TYPES_TO_REMOVE] ?? $configuration;
Assert::isArray($parentTypesToRemove);
Assert::allString($parentTypesToRemove);

View File

@ -95,7 +95,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$traitsToRemove = $configuration[self::TRAITS_TO_REMOVE] ?? ($configuration ?: []);
$traitsToRemove = $configuration[self::TRAITS_TO_REMOVE] ?? $configuration;
Assert::allString($traitsToRemove);
/** @var string[] $traitsToRemove */

View File

@ -83,12 +83,12 @@ CODE_SAMPLE
}
/**
* @param array<string, RemoveFuncCallArg[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$removedFunctionArguments = $configuration[self::REMOVED_FUNCTION_ARGUMENTS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($removedFunctionArguments, RemoveFuncCallArg::class);
$removedFunctionArguments = $configuration[self::REMOVED_FUNCTION_ARGUMENTS] ?? $configuration;
Assert::allIsAOf($removedFunctionArguments, RemoveFuncCallArg::class);
$this->removedFunctionArguments = $removedFunctionArguments;
}
}

View File

@ -93,12 +93,12 @@ CODE_SAMPLE
}
/**
* @param array<string, RemoveFuncCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$removeFuncCalls = $configuration[self::REMOVE_FUNC_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($removeFuncCalls, RemoveFuncCall::class);
$removeFuncCalls = $configuration[self::REMOVE_FUNC_CALLS] ?? $configuration;
Assert::allIsAOf($removeFuncCalls, RemoveFuncCall::class);
$this->removeFuncCalls = $removeFuncCalls;
}

View File

@ -68,7 +68,7 @@ CODE_SAMPLE
}
/**
* @return class-string[]
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{

View File

@ -132,7 +132,7 @@ final class ClassRenamer
$stringName = $this->nodeNameResolver->getName($name);
$newName = $oldToNewClasses[$stringName] ?? null;
if (! $newName) {
if ($newName === null) {
return null;
}
@ -236,7 +236,7 @@ final class ClassRenamer
$className = (string) $this->nodeNameResolver->getName($classLike);
$newName = $oldToNewClasses[$className] ?? null;
if (! $newName) {
if ($newName === null) {
return null;
}
@ -258,7 +258,7 @@ final class ClassRenamer
$classNamingGetNamespace = $this->classNaming->getNamespace($className);
// Old class did not have any namespace, we need to wrap class with Namespace_ node
if ($newNamespacePart && ! $classNamingGetNamespace) {
if ($newNamespacePart !== null && $classNamingGetNamespace === null) {
$this->changeNameToFullyQualifiedName($classLike);
$name = new Name($newNamespacePart);

View File

@ -96,12 +96,12 @@ CODE_SAMPLE
}
/**
* @param array<string, RenameClassConstFetchInterface[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$renameClassConstFetches = $configuration[self::CLASS_CONSTANT_RENAME] ?? ($configuration ?: []);
Assert::allIsInstanceOf($renameClassConstFetches, RenameClassConstFetchInterface::class);
$renameClassConstFetches = $configuration[self::CLASS_CONSTANT_RENAME] ?? $configuration;
Assert::allIsAOf($renameClassConstFetches, RenameClassConstFetchInterface::class);
$this->renameClassConstFetches = $renameClassConstFetches;
}

View File

@ -112,12 +112,12 @@ CODE_SAMPLE
}
/**
* @param array<string, RenameAnnotation[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$renamedAnnotationsInTypes = $configuration[self::RENAMED_ANNOTATIONS_IN_TYPES] ?? ($configuration ?: []);
Assert::allIsInstanceOf($renamedAnnotationsInTypes, RenameAnnotation::class);
$renamedAnnotationsInTypes = $configuration[self::RENAMED_ANNOTATIONS_IN_TYPES] ?? $configuration;
Assert::allIsAOf($renamedAnnotationsInTypes, RenameAnnotation::class);
$this->renamedAnnotations = $renamedAnnotationsInTypes;
}
}

View File

@ -92,7 +92,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$oldToNewConstants = $configuration[self::OLD_TO_NEW_CONSTANTS] ?? ($configuration ?: []);
$oldToNewConstants = $configuration[self::OLD_TO_NEW_CONSTANTS] ?? $configuration;
Assert::allString(array_keys($oldToNewConstants));
Assert::allString($oldToNewConstants);

View File

@ -98,7 +98,7 @@ CODE_SAMPLE
$node->stmts = $stmts;
// add a new namespace?
if ($this->newNamespace) {
if ($this->newNamespace !== null) {
$namespace = new Namespace_(new Name($this->newNamespace));
$namespace->stmts = $stmts;
@ -115,12 +115,12 @@ CODE_SAMPLE
}
/**
* @param array<string, PseudoNamespaceToNamespace[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$namespacePrefixesWithExcludedClasses = $configuration[self::NAMESPACE_PREFIXES_WITH_EXCLUDED_CLASSES] ?? ($configuration ?: []);
Assert::allIsInstanceOf($namespacePrefixesWithExcludedClasses, PseudoNamespaceToNamespace::class);
$namespacePrefixesWithExcludedClasses = $configuration[self::NAMESPACE_PREFIXES_WITH_EXCLUDED_CLASSES] ?? $configuration;
Assert::allIsAOf($namespacePrefixesWithExcludedClasses, PseudoNamespaceToNamespace::class);
$this->pseudoNamespacesToNamespaces = $namespacePrefixesWithExcludedClasses;
}
@ -170,7 +170,7 @@ CODE_SAMPLE
}
$excludedClasses = $pseudoNamespaceToNamespace->getExcludedClasses();
if (is_array($excludedClasses) && $this->isNames($node, $excludedClasses)) {
if ($excludedClasses !== [] && $this->isNames($node, $excludedClasses)) {
return null;
}
@ -187,10 +187,7 @@ CODE_SAMPLE
private function processName(Name $name): Name
{
$nodeName = $this->getName($name);
if ($nodeName !== null) {
$name->parts = explode('_', $nodeName);
}
$name->parts = explode('_', $nodeName);
return $name;
}

View File

@ -64,7 +64,7 @@ final class RenameFunctionRector extends AbstractRector implements ConfigurableR
}
// not to refactor here
$isVirtual = $node->name->getAttribute(AttributeKey::VIRTUAL_NODE);
$isVirtual = (bool) $node->name->getAttribute(AttributeKey::VIRTUAL_NODE, false);
if ($isVirtual) {
continue;
}
@ -77,13 +77,15 @@ final class RenameFunctionRector extends AbstractRector implements ConfigurableR
}
/**
* @param array<string, mixed[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$oldFunctionToNewFunction = $configuration[self::OLD_FUNCTION_TO_NEW_FUNCTION] ?? $configuration ?: [];
Assert::allString($oldFunctionToNewFunction);
$oldFunctionToNewFunction = $configuration[self::OLD_FUNCTION_TO_NEW_FUNCTION] ?? $configuration;
Assert::isArray($oldFunctionToNewFunction);
Assert::allString(array_values($oldFunctionToNewFunction));
Assert::allString($oldFunctionToNewFunction);
$this->oldFunctionToNewFunction = $oldFunctionToNewFunction;
}

View File

@ -118,12 +118,12 @@ CODE_SAMPLE
}
/**
* @param array<string, MethodCallRenameInterface[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$methodCallRenames = $configuration[self::METHOD_CALL_RENAMES] ?? ($configuration ?: []);
Assert::allIsInstanceOf($methodCallRenames, MethodCallRenameInterface::class);
$methodCallRenames = $configuration[self::METHOD_CALL_RENAMES] ?? $configuration;
Assert::allIsAOf($methodCallRenames, MethodCallRenameInterface::class);
$this->methodCallRenames = $methodCallRenames;
$this->methodCallRenameCollector->addMethodCallRenames($methodCallRenames);

View File

@ -114,7 +114,7 @@ CODE_SAMPLE
}
/**
* @param array<string, mixed[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
@ -132,7 +132,7 @@ CODE_SAMPLE
private function processCleanUpUse(Use_ $use, array $oldToNewClasses): ?Use_
{
foreach ($use->uses as $useUse) {
if ($useUse->name instanceof Name && ! $useUse->alias instanceof Identifier && isset($oldToNewClasses[$useUse->name->toString()])) {
if (! $useUse->alias instanceof Identifier && isset($oldToNewClasses[$useUse->name->toString()])) {
$this->removeNode($use);
return $use;
}
@ -142,7 +142,7 @@ CODE_SAMPLE
}
/**
* @param array<string, string> $oldToNewClasses
* @param mixed[] $oldToNewClasses
*/
private function addOldToNewClasses(array $oldToNewClasses): void
{

View File

@ -125,7 +125,7 @@ final class RenameNamespaceRector extends AbstractRector implements Configurable
*/
public function configure(array $configuration): void
{
$oldToNewNamespaces = $configuration[self::OLD_TO_NEW_NAMESPACES] ?? ($configuration ?: []);
$oldToNewNamespaces = $configuration[self::OLD_TO_NEW_NAMESPACES] ?? $configuration;
Assert::allString(array_keys($oldToNewNamespaces));
Assert::allString($oldToNewNamespaces);

View File

@ -71,12 +71,12 @@ final class RenamePropertyRector extends AbstractRector implements ConfigurableR
}
/**
* @param array<string, RenameProperty[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$renamedProperties = $configuration[self::RENAMED_PROPERTIES] ?? ($configuration ?: []);
Assert::allIsInstanceOf($renamedProperties, RenameProperty::class);
$renamedProperties = $configuration[self::RENAMED_PROPERTIES] ?? $configuration;
Assert::allIsAOf($renamedProperties, RenameProperty::class);
$this->renamedProperties = $renamedProperties;
}

View File

@ -92,12 +92,12 @@ final class RenameStaticMethodRector extends AbstractRector implements Configura
}
/**
* @param array<string, RenameStaticMethod[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$oldToNewMethodsByClasses = $configuration[self::OLD_TO_NEW_METHODS_BY_CLASSES];
Assert::allIsInstanceOf($oldToNewMethodsByClasses, RenameStaticMethod::class);
Assert::allIsAOf($oldToNewMethodsByClasses, RenameStaticMethod::class);
$this->staticMethodRenames = $oldToNewMethodsByClasses;
}

View File

@ -87,13 +87,15 @@ CODE_SAMPLE
}
/**
* @param array<string, array<string, string>> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$stringChanges = $configuration[self::STRING_CHANGES] ?? ($configuration ?: []);
$stringChanges = $configuration[self::STRING_CHANGES] ?? $configuration;
Assert::isArray($stringChanges);
Assert::allString(array_keys($stringChanges));
Assert::allString($stringChanges);
Assert::allString(array_values($stringChanges));
$this->stringChanges = $stringChanges;
}

View File

@ -102,12 +102,12 @@ CODE_SAMPLE
}
/**
* @param array<string, CompleteImportForPartialAnnotation[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$useImportsToRestore = $configuration[self::USE_IMPORTS_TO_RESTORE] ?? ($configuration ?: []);
Assert::allIsInstanceOf($useImportsToRestore, CompleteImportForPartialAnnotation::class);
$useImportsToRestore = $configuration[self::USE_IMPORTS_TO_RESTORE] ?? $configuration;
Assert::allIsAOf($useImportsToRestore, CompleteImportForPartialAnnotation::class);
$default = [
new CompleteImportForPartialAnnotation('Doctrine\ORM\Mapping', 'ORM'),

View File

@ -21,7 +21,7 @@ abstract class AbstractFalsyScalarRuleFixerRector extends AbstractRector impleme
protected bool $treatAsNonEmpty = false;
/**
* @param array<string, mixed> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{

View File

@ -114,12 +114,12 @@ CODE_SAMPLE
}
/**
* @param array<string, DimFetchAssignToMethodCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$dimFetchAssignToMethodCalls = $configuration[self::DIM_FETCH_ASSIGN_TO_METHOD_CALL] ?? ($configuration ?: []);
Assert::allIsInstanceOf($dimFetchAssignToMethodCalls, DimFetchAssignToMethodCall::class);
$dimFetchAssignToMethodCalls = $configuration[self::DIM_FETCH_ASSIGN_TO_METHOD_CALL] ?? $configuration;
Assert::allIsAOf($dimFetchAssignToMethodCalls, DimFetchAssignToMethodCall::class);
$this->dimFetchAssignToMethodCalls = $dimFetchAssignToMethodCalls;
}

View File

@ -94,7 +94,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$getAndSetToMethodCalls = $configuration[self::TYPE_TO_METHOD_CALLS] ?? ($configuration ?: []);
$getAndSetToMethodCalls = $configuration[self::TYPE_TO_METHOD_CALLS] ?? $configuration;
Assert::allIsAOf($getAndSetToMethodCalls, GetAndSetToMethodCall::class);
$this->getAndSetToMethodCalls = $getAndSetToMethodCalls;

View File

@ -95,12 +95,12 @@ CODE_SAMPLE
}
/**
* @param array<string, PropertyAssignToMethodCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$propertyAssignsToMethodCalls = $configuration[self::PROPERTY_ASSIGNS_TO_METHODS_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($propertyAssignsToMethodCalls, PropertyAssignToMethodCall::class);
$propertyAssignsToMethodCalls = $configuration[self::PROPERTY_ASSIGNS_TO_METHODS_CALLS] ?? $configuration;
Assert::allIsAOf($propertyAssignsToMethodCalls, PropertyAssignToMethodCall::class);
$this->propertyAssignsToMethodCalls = $propertyAssignsToMethodCalls;
}
}

View File

@ -97,12 +97,12 @@ CODE_SAMPLE
}
/**
* @param array<string, PropertyFetchToMethodCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$propertiesToMethodCalls = $configuration[self::PROPERTIES_TO_METHOD_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($propertiesToMethodCalls, PropertyFetchToMethodCall::class);
$propertiesToMethodCalls = $configuration[self::PROPERTIES_TO_METHOD_CALLS] ?? $configuration;
Assert::allIsAOf($propertiesToMethodCalls, PropertyFetchToMethodCall::class);
$this->propertiesToMethodCalls = $propertiesToMethodCalls;
}

View File

@ -119,7 +119,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$attributeKeysToClassConstFetches = $configuration[self::ATTRIBUTE_KEYS_TO_CLASS_CONST_FETCHES] ?? ($configuration ?: []);
$attributeKeysToClassConstFetches = $configuration[self::ATTRIBUTE_KEYS_TO_CLASS_CONST_FETCHES] ?? $configuration;
Assert::allIsAOf($attributeKeysToClassConstFetches, AttributeKeyToClassConstFetch::class);
$this->attributeKeysToClassConstFetches = $attributeKeysToClassConstFetches;

View File

@ -76,12 +76,12 @@ final class ClassConstFetchToValueRector extends AbstractRector implements Confi
}
/**
* @param array<string, ClassConstFetchToValue[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$classConstFetchesToValues = $configuration[self::CLASS_CONST_FETCHES_TO_VALUES] ?? ($configuration ?: []);
Assert::allIsInstanceOf($classConstFetchesToValues, ClassConstFetchToValue::class);
$classConstFetchesToValues = $configuration[self::CLASS_CONST_FETCHES_TO_VALUES] ?? $configuration;
Assert::allIsAOf($classConstFetchesToValues, ClassConstFetchToValue::class);
$this->classConstFetchesToValues = $classConstFetchesToValues;
}

View File

@ -114,12 +114,12 @@ CODE_SAMPLE
}
/**
* @param array<string, SingleToManyMethod[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$singleToManyMethods = $configuration[self::SINGLES_TO_MANY_METHODS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($singleToManyMethods, SingleToManyMethod::class);
$singleToManyMethods = $configuration[self::SINGLES_TO_MANY_METHODS] ?? $configuration;
Assert::allIsAOf($singleToManyMethods, SingleToManyMethod::class);
$this->singleToManyMethods = $singleToManyMethods;
}

View File

@ -84,7 +84,7 @@ CODE_SAMPLE
continue;
}
if (! $node->stmts) {
if ($node->stmts === null) {
continue;
}
@ -95,12 +95,12 @@ CODE_SAMPLE
}
/**
* @param array<string, WrapReturn[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$typeMethodWraps = $configuration[self::TYPE_METHOD_WRAPS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($typeMethodWraps, WrapReturn::class);
$typeMethodWraps = $configuration[self::TYPE_METHOD_WRAPS] ?? $configuration;
Assert::allIsAOf($typeMethodWraps, WrapReturn::class);
$this->typeMethodWraps = $typeMethodWraps;
}

View File

@ -106,7 +106,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$interfaceByParent = $configuration[self::INTERFACE_BY_PARENT] ?? ($configuration ?: []);
$interfaceByParent = $configuration[self::INTERFACE_BY_PARENT] ?? $configuration;
Assert::isArray($interfaceByParent);
Assert::allString(array_keys($interfaceByParent));

View File

@ -97,11 +97,11 @@ CODE_SAMPLE
/**
* @todo complex configuration, introduce value object!
* @param array<string, array<string, string>> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$interfaceByTrait = $configuration[self::INTERFACE_BY_TRAIT] ?? ($configuration ?: []);
$interfaceByTrait = $configuration[self::INTERFACE_BY_TRAIT] ?? $configuration;
Assert::isArray($interfaceByTrait);
Assert::allString(array_keys($interfaceByTrait));

View File

@ -91,12 +91,13 @@ CODE_SAMPLE
}
/**
* @param array<string, array<string, string>> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$oldToNewInterfaces = $configuration[self::OLD_TO_NEW_INTERFACES] ?? ($configuration ?: []);
$oldToNewInterfaces = $configuration[self::OLD_TO_NEW_INTERFACES] ?? $configuration;
Assert::isArray($oldToNewInterfaces);
Assert::allString(array_keys($oldToNewInterfaces));
Assert::allString($oldToNewInterfaces);

View File

@ -105,12 +105,12 @@ CODE_SAMPLE
}
/**
* @param array<string, ParentClassToTraits[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$parentClassToTraits = $configuration[self::PARENT_CLASS_TO_TRAITS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($parentClassToTraits, ParentClassToTraits::class);
$parentClassToTraits = $configuration[self::PARENT_CLASS_TO_TRAITS] ?? $configuration;
Assert::allIsAOf($parentClassToTraits, ParentClassToTraits::class);
$this->parentClassToTraits = $parentClassToTraits;
}

View File

@ -143,17 +143,17 @@ CODE_SAMPLE
}
/**
* @param array<string, array<ArgumentFuncCallToMethodCall|ArrayFuncCallToMethodCall>> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$functionToMethodCalls = $configuration[self::FUNCTIONS_TO_METHOD_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($functionToMethodCalls, ArgumentFuncCallToMethodCall::class);
$functionToMethodCalls = $configuration[self::FUNCTIONS_TO_METHOD_CALLS] ?? $configuration;
Assert::allIsAOf($functionToMethodCalls, ArgumentFuncCallToMethodCall::class);
$this->argumentFuncCallToMethodCalls = $functionToMethodCalls;
$arrayFunctionsToMethodCalls = $configuration[self::ARRAY_FUNCTIONS_TO_METHOD_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($arrayFunctionsToMethodCalls, ArrayFuncCallToMethodCall::class);
$arrayFunctionsToMethodCalls = $configuration[self::ARRAY_FUNCTIONS_TO_METHOD_CALLS] ?? $configuration;
Assert::allIsAOf($arrayFunctionsToMethodCalls, ArrayFuncCallToMethodCall::class);
$this->arrayFunctionsToMethodCalls = $arrayFunctionsToMethodCalls;
}
@ -237,12 +237,8 @@ CODE_SAMPLE
ArgumentFuncCallToMethodCall $argumentFuncCallToMethodCall,
PropertyFetch $propertyFetch
): MethodCall | PropertyFetch {
if ($argumentFuncCallToMethodCall->getMethodIfNoArgs()) {
if ($argumentFuncCallToMethodCall->getMethodIfNoArgs() !== null) {
$methodName = $argumentFuncCallToMethodCall->getMethodIfNoArgs();
if (! is_string($methodName)) {
throw new ShouldNotHappenException();
}
return new MethodCall($propertyFetch, $methodName);
}
@ -276,9 +272,7 @@ CODE_SAMPLE
return null;
}
if ($arrayFuncCallToMethodCall->getArrayMethod() && $this->arrayTypeAnalyzer->isArrayType(
$funcCall->args[0]->value
)) {
if ($this->arrayTypeAnalyzer->isArrayType($funcCall->args[0]->value)) {
return new MethodCall($propertyFetch, $arrayFuncCallToMethodCall->getArrayMethod(), $funcCall->args);
}
@ -286,10 +280,6 @@ CODE_SAMPLE
return null;
}
if ($this->arrayTypeAnalyzer->isArrayType($funcCall->args[0]->value)) {
return null;
}
return new MethodCall($propertyFetch, $arrayFuncCallToMethodCall->getNonArrayMethod(), $funcCall->args);
}
}

View File

@ -77,7 +77,7 @@ CODE_SAMPLE
public function refactor(Node $node): ?Node
{
$functionName = $this->getName($node);
if (! $functionName) {
if (! is_string($functionName)) {
return null;
}
@ -89,11 +89,12 @@ CODE_SAMPLE
}
/**
* @param array<string, string[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$functionsToConstants = $configuration[self::FUNCTIONS_TO_CONSTANTS] ?? ($configuration ?: []);
$functionsToConstants = $configuration[self::FUNCTIONS_TO_CONSTANTS] ?? $configuration;
Assert::isArray($functionsToConstants);
Assert::allString($functionsToConstants);
Assert::allString(array_keys($functionsToConstants));

View File

@ -128,13 +128,13 @@ CODE_SAMPLE
}
/**
* @param array<string, FuncCallToMethodCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$funcCallsToClassMethodCalls = $configuration[self::FUNC_CALL_TO_CLASS_METHOD_CALL] ?? ($configuration ?: []);
$funcCallsToClassMethodCalls = $configuration[self::FUNC_CALL_TO_CLASS_METHOD_CALL] ?? $configuration;
Assert::isArray($funcCallsToClassMethodCalls);
Assert::allIsInstanceOf($funcCallsToClassMethodCalls, FuncCallToMethodCall::class);
Assert::allIsAOf($funcCallsToClassMethodCalls, FuncCallToMethodCall::class);
$this->funcNameToMethodCallNames = $funcCallsToClassMethodCalls;
}

View File

@ -12,6 +12,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToNewRector\FuncCallToNewRectorTest
@ -86,10 +87,15 @@ CODE_SAMPLE
}
/**
* @param array<string, mixed> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$this->functionToNew = $configuration[self::FUNCTIONS_TO_NEWS] ?? ($configuration ?: []);
$functionsToNews = $configuration[self::FUNCTIONS_TO_NEWS] ?? $configuration;
Assert::isArray($functionsToNews);
Assert::allString($functionsToNews);
$this->functionToNew = $functionsToNews;
}
}

View File

@ -72,12 +72,14 @@ final class FuncCallToStaticCallRector extends AbstractRector implements Configu
}
/**
* @param array<string, FuncCallToStaticCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$funcCallsToStaticCalls = $configuration[self::FUNC_CALLS_TO_STATIC_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($funcCallsToStaticCalls, FuncCallToStaticCall::class);
$funcCallsToStaticCalls = $configuration[self::FUNC_CALLS_TO_STATIC_CALLS] ?? $configuration;
Assert::isArray($funcCallsToStaticCalls);
Assert::allIsAOf($funcCallsToStaticCalls, FuncCallToStaticCall::class);
$this->funcCallsToStaticCalls = $funcCallsToStaticCalls;
}
}

View File

@ -89,12 +89,13 @@ CODE_SAMPLE
}
/**
* @param array<string, UnsetAndIssetToMethodCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$issetUnsetToMethodCalls = $configuration[self::ISSET_UNSET_TO_METHOD_CALL] ?? ($configuration ?: []);
Assert::allIsInstanceOf($issetUnsetToMethodCalls, UnsetAndIssetToMethodCall::class);
$issetUnsetToMethodCalls = $configuration[self::ISSET_UNSET_TO_METHOD_CALL] ?? $configuration;
Assert::isArray($issetUnsetToMethodCalls);
Assert::allIsAOf($issetUnsetToMethodCalls, UnsetAndIssetToMethodCall::class);
$this->issetUnsetToMethodCalls = $issetUnsetToMethodCalls;
}

View File

@ -124,12 +124,13 @@ CODE_SAMPLE
}
/**
* @param array<string, CallableInMethodCallToVariable[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$callableInMethodCallToVariable = $configuration[self::CALLABLE_IN_METHOD_CALL_TO_VARIABLE] ?? ($configuration ?: []);
Assert::allIsInstanceOf($callableInMethodCallToVariable, CallableInMethodCallToVariable::class);
$callableInMethodCallToVariable = $configuration[self::CALLABLE_IN_METHOD_CALL_TO_VARIABLE] ?? $configuration;
Assert::isArray($callableInMethodCallToVariable);
Assert::allIsAOf($callableInMethodCallToVariable, CallableInMethodCallToVariable::class);
$this->callableInMethodCallToVariable = $callableInMethodCallToVariable;
}

View File

@ -89,15 +89,15 @@ CODE_SAMPLE
}
/**
* @param array<string, MethodCallToAnotherMethodCallWithArguments[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$methodCallRenamesWithAddedArguments = $configuration[self::METHOD_CALL_RENAMES_WITH_ADDED_ARGUMENTS] ?? ($configuration ?: []);
Assert::allIsInstanceOf(
$methodCallRenamesWithAddedArguments,
MethodCallToAnotherMethodCallWithArguments::class
);
$methodCallRenamesWithAddedArguments = $configuration[self::METHOD_CALL_RENAMES_WITH_ADDED_ARGUMENTS] ?? $configuration;
Assert::isArray($methodCallRenamesWithAddedArguments);
Assert::allIsAOf($methodCallRenamesWithAddedArguments, MethodCallToAnotherMethodCallWithArguments::class);
$this->methodCallRenamesWithAddedArguments = $methodCallRenamesWithAddedArguments;
}
}

View File

@ -142,7 +142,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$methodCallsToMethodsCalls = $configuration[self::METHOD_CALLS_TO_METHOD_CALLS] ?? ($configuration ?: []);
$methodCallsToMethodsCalls = $configuration[self::METHOD_CALLS_TO_METHOD_CALLS] ?? $configuration;
Assert::allIsAOf($methodCallsToMethodsCalls, MethodCallToMethodCall::class);
$this->methodCallsToMethodsCalls = $methodCallsToMethodsCalls;

View File

@ -90,7 +90,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$methodCallToPropertyFetchCollection = $configuration[self::METHOD_CALL_TO_PROPERTY_FETCHES] ?? ($configuration ?: []);
$methodCallToPropertyFetchCollection = $configuration[self::METHOD_CALL_TO_PROPERTY_FETCHES] ?? $configuration;
Assert::allString(array_keys($methodCallToPropertyFetchCollection));
Assert::allString($methodCallToPropertyFetchCollection);

View File

@ -108,12 +108,14 @@ CODE_SAMPLE
}
/**
* @param array<string, MethodCallToStaticCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$methodCallsToStaticCalls = $configuration[self::METHOD_CALLS_TO_STATIC_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($methodCallsToStaticCalls, MethodCallToStaticCall::class);
$methodCallsToStaticCalls = $configuration[self::METHOD_CALLS_TO_STATIC_CALLS] ?? $configuration;
Assert::isArray($methodCallsToStaticCalls);
Assert::allIsAOf($methodCallsToStaticCalls, MethodCallToStaticCall::class);
$this->methodCallsToStaticCalls = $methodCallsToStaticCalls;
}
}

View File

@ -94,12 +94,12 @@ CODE_SAMPLE
}
/**
* @param array<string, ReplaceParentCallByPropertyCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$parentCallToProperties = $configuration[self::PARENT_CALLS_TO_PROPERTIES] ?? ($configuration ?: []);
Assert::allIsInstanceOf($parentCallToProperties, ReplaceParentCallByPropertyCall::class);
$parentCallToProperties = $configuration[self::PARENT_CALLS_TO_PROPERTIES] ?? $configuration;
Assert::allIsAOf($parentCallToProperties, ReplaceParentCallByPropertyCall::class);
$this->parentCallToProperties = $parentCallToProperties;
}

View File

@ -168,12 +168,14 @@ CODE_SAMPLE
}
/**
* @param array<string, ServiceGetterToConstructorInjection[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$methodCallToServices = $configuration[self::METHOD_CALL_TO_SERVICES] ?? ($configuration ?: []);
Assert::allIsInstanceOf($methodCallToServices, ServiceGetterToConstructorInjection::class);
$methodCallToServices = $configuration[self::METHOD_CALL_TO_SERVICES] ?? $configuration;
Assert::isArray($methodCallToServices);
Assert::allIsAOf($methodCallToServices, ServiceGetterToConstructorInjection::class);
$this->methodCallToServices = $methodCallToServices;
}
}

View File

@ -104,12 +104,14 @@ CODE_SAMPLE
}
/**
* @param array<string, NewArgToMethodCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$newArgsToMethodCalls = $configuration[self::NEW_ARGS_TO_METHOD_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($newArgsToMethodCalls, NewArgToMethodCall::class);
$newArgsToMethodCalls = $configuration[self::NEW_ARGS_TO_METHOD_CALLS] ?? $configuration;
Assert::isArray($newArgsToMethodCalls);
Assert::allIsAOf($newArgsToMethodCalls, NewArgToMethodCall::class);
$this->newArgsToMethodCalls = $newArgsToMethodCalls;
}
}

View File

@ -21,6 +21,7 @@ use Rector\PostRector\ValueObject\PropertyMetadata;
use Rector\Transform\NodeFactory\PropertyFetchFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
/**
* @see \Rector\Tests\Transform\Rector\New_\NewToConstructorInjectionRector\NewToConstructorInjectionRectorTest
@ -116,11 +117,13 @@ CODE_SAMPLE
}
/**
* @param array<string, mixed[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$typesToConstructorInjections = $configuration[self::TYPES_TO_CONSTRUCTOR_INJECTION] ?? ($configuration ?: []);
$typesToConstructorInjections = $configuration[self::TYPES_TO_CONSTRUCTOR_INJECTION] ?? $configuration;
Assert::isArray($typesToConstructorInjections);
foreach ($typesToConstructorInjections as $typeToConstructorInjection) {
$this->constructorInjectionObjectTypes[] = new ObjectType($typeToConstructorInjection);
}

View File

@ -136,12 +136,14 @@ CODE_SAMPLE
}
/**
* @param array<string, NewToMethodCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$newsToMethodCalls = $configuration[self::NEWS_TO_METHOD_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($newsToMethodCalls, NewToMethodCall::class);
$newsToMethodCalls = $configuration[self::NEWS_TO_METHOD_CALLS] ?? $configuration;
Assert::isArray($newsToMethodCalls);
Assert::allIsAOf($newsToMethodCalls, NewToMethodCall::class);
$this->newsToMethodCalls = $newsToMethodCalls;
}

View File

@ -88,12 +88,14 @@ CODE_SAMPLE
}
/**
* @param array<string, NewToStaticCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$typeToStaticCalls = $configuration[self::TYPE_TO_STATIC_CALLS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($typeToStaticCalls, NewToStaticCall::class);
$typeToStaticCalls = $configuration[self::TYPE_TO_STATIC_CALLS] ?? $configuration;
Assert::isArray($typeToStaticCalls);
Assert::allIsAOf($typeToStaticCalls, NewToStaticCall::class);
$this->typeToStaticCalls = $typeToStaticCalls;
}
}

View File

@ -77,12 +77,14 @@ final class StaticCallToFuncCallRector extends AbstractRector implements Configu
}
/**
* @param array<string, StaticCallToFuncCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$staticCallsToFunctions = $configuration[self::STATIC_CALLS_TO_FUNCTIONS] ?? ($configuration ?: []);
Assert::allIsInstanceOf($staticCallsToFunctions, StaticCallToFuncCall::class);
$staticCallsToFunctions = $configuration[self::STATIC_CALLS_TO_FUNCTIONS] ?? $configuration;
Assert::isArray($staticCallsToFunctions);
Assert::allIsAOf($staticCallsToFunctions, StaticCallToFuncCall::class);
$this->staticCallsToFunctions = $staticCallsToFunctions;
}
}

View File

@ -148,13 +148,13 @@ CODE_SAMPLE
}
/**
* @param array<string, StaticCallToMethodCall[]> $configuration
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$staticCallsToMethodCalls = $configuration[self::STATIC_CALLS_TO_METHOD_CALLS] ?? ($configuration ?: []);
$staticCallsToMethodCalls = $configuration[self::STATIC_CALLS_TO_METHOD_CALLS] ?? $configuration;
Assert::isArray($staticCallsToMethodCalls);
Assert::allIsInstanceOf($staticCallsToMethodCalls, StaticCallToMethodCall::class);
Assert::allIsAOf($staticCallsToMethodCalls, StaticCallToMethodCall::class);
$this->staticCallsToMethodCalls = $staticCallsToMethodCalls;
}

View File

@ -101,7 +101,7 @@ CODE_SAMPLE
*/
public function configure(array $configuration): void
{
$staticCallsToNews = $configuration[self::STATIC_CALLS_TO_NEWS] ?? ($configuration ?: []);
$staticCallsToNews = $configuration[self::STATIC_CALLS_TO_NEWS] ?? $configuration;
Assert::allIsAOf($staticCallsToNews, StaticCallToNew::class);
$this->staticCallsToNews = $staticCallsToNews;

Some files were not shown because too many files have changed in this diff Show More