Updated Rector to commit 24a32dfefb

24a32dfefb Fix docs double import (#478)
This commit is contained in:
Tomas Votruba 2021-07-21 13:46:30 +00:00
parent d15985c4e5
commit e3f99041de
56 changed files with 236 additions and 234 deletions

View File

@ -53,8 +53,9 @@ final class TypeFactory
return $this->createUnionOrSingleType($types);
}
/**
* @param Type[] $types
* @return Type[]
* @template TType as Type
* @param array<TType> $types
* @return array<TType>
*/
public function uniquateTypes(array $types, bool $keepConstant = \false) : array
{

View File

@ -14,6 +14,8 @@ use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper;
use Rector\Core\Configuration\Option;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\ValueObject\Application\File;
use Rector\PostRector\Collector\UseNodesToAddCollector;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
@ -41,12 +43,17 @@ final class NameImportingPhpDocNodeVisitor extends \RectorPrefix20210721\Symplif
* @var \Rector\PostRector\Collector\UseNodesToAddCollector
*/
private $useNodesToAddCollector;
public function __construct(\Rector\StaticTypeMapper\StaticTypeMapper $staticTypeMapper, \RectorPrefix20210721\Symplify\PackageBuilder\Parameter\ParameterProvider $parameterProvider, \Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper $classNameImportSkipper, \Rector\PostRector\Collector\UseNodesToAddCollector $useNodesToAddCollector)
/**
* @var \Rector\Core\Provider\CurrentFileProvider
*/
private $currentFileProvider;
public function __construct(\Rector\StaticTypeMapper\StaticTypeMapper $staticTypeMapper, \RectorPrefix20210721\Symplify\PackageBuilder\Parameter\ParameterProvider $parameterProvider, \Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper $classNameImportSkipper, \Rector\PostRector\Collector\UseNodesToAddCollector $useNodesToAddCollector, \Rector\Core\Provider\CurrentFileProvider $currentFileProvider)
{
$this->staticTypeMapper = $staticTypeMapper;
$this->parameterProvider = $parameterProvider;
$this->classNameImportSkipper = $classNameImportSkipper;
$this->useNodesToAddCollector = $useNodesToAddCollector;
$this->currentFileProvider = $currentFileProvider;
}
public function beforeTraverse(\PHPStan\PhpDocParser\Ast\Node $node) : void
{
@ -74,39 +81,47 @@ final class NameImportingPhpDocNodeVisitor extends \RectorPrefix20210721\Symplif
if ($this->shouldSkipShortClassName($staticType)) {
return null;
}
return $this->processFqnNameImport($this->currentPhpParserNode, $node, $staticType);
$file = $this->currentFileProvider->getFile();
if (!$file instanceof \Rector\Core\ValueObject\Application\File) {
return null;
}
return $this->processFqnNameImport($this->currentPhpParserNode, $node, $staticType, $file);
}
public function setCurrentNode(\PhpParser\Node $phpParserNode) : void
{
$this->currentPhpParserNode = $phpParserNode;
}
private function processFqnNameImport(\PhpParser\Node $phpParserNode, \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode $identifierTypeNode, \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType) : ?\PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode
private function processFqnNameImport(\PhpParser\Node $phpParserNode, \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode $identifierTypeNode, \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType, \Rector\Core\ValueObject\Application\File $file) : ?\PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode
{
if ($this->classNameImportSkipper->shouldSkipNameForFullyQualifiedObjectType($phpParserNode, $fullyQualifiedObjectType)) {
return $identifierTypeNode;
if ($this->classNameImportSkipper->shouldSkipNameForFullyQualifiedObjectType($file, $phpParserNode, $fullyQualifiedObjectType)) {
return null;
}
$parent = $identifierTypeNode->getAttribute(\Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey::PARENT);
if ($parent instanceof \PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode) {
// might break
return null;
}
// should skip because its already used
if ($this->useNodesToAddCollector->isShortImported($phpParserNode, $fullyQualifiedObjectType)) {
if ($this->useNodesToAddCollector->isImportShortable($phpParserNode, $fullyQualifiedObjectType)) {
$newNode = new \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode($fullyQualifiedObjectType->getShortName());
if ($newNode->name !== $identifierTypeNode->name) {
return $newNode;
}
return $identifierTypeNode;
}
return $identifierTypeNode;
}
$this->useNodesToAddCollector->addUseImport($fullyQualifiedObjectType);
$newNode = new \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode($fullyQualifiedObjectType->getShortName());
// should skip because its already used
if ($this->useNodesToAddCollector->isShortImported($file, $fullyQualifiedObjectType)) {
if (!$this->useNodesToAddCollector->isImportShortable($file, $fullyQualifiedObjectType)) {
return null;
}
if ($newNode->name !== $identifierTypeNode->name) {
$this->useNodesToAddCollector->addUseImport($fullyQualifiedObjectType);
return $newNode;
}
return null;
}
if ($newNode->name !== $identifierTypeNode->name) {
// do not import twice
if ($this->useNodesToAddCollector->isShortImported($file, $fullyQualifiedObjectType)) {
return null;
}
$this->useNodesToAddCollector->addUseImport($fullyQualifiedObjectType);
return $newNode;
}
return $identifierTypeNode;
return null;
}
private function shouldSkipShortClassName(\Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType) : bool
{
@ -126,7 +141,11 @@ final class NameImportingPhpDocNodeVisitor extends \RectorPrefix20210721\Symplif
}
$staticType = new \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType($staticType->getClassName());
}
$shortentedIdentifierTypeNode = $this->processFqnNameImport($this->currentPhpParserNode, $identifierTypeNode, $staticType);
$file = $this->currentFileProvider->getFile();
if (!$file instanceof \Rector\Core\ValueObject\Application\File) {
return;
}
$shortentedIdentifierTypeNode = $this->processFqnNameImport($this->currentPhpParserNode, $identifierTypeNode, $staticType, $file);
if (!$shortentedIdentifierTypeNode instanceof \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode) {
return;
}
@ -154,7 +173,11 @@ final class NameImportingPhpDocNodeVisitor extends \RectorPrefix20210721\Symplif
}
$staticType = new \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType($staticType->getClassName());
}
$importedName = $this->processFqnNameImport($this->currentPhpParserNode, $identifierTypeNode, $staticType);
$file = $this->currentFileProvider->getFile();
if (!$file instanceof \Rector\Core\ValueObject\Application\File) {
return null;
}
$importedName = $this->processFqnNameImport($this->currentPhpParserNode, $identifierTypeNode, $staticType, $file);
if ($importedName !== null) {
$spacelessPhpDocTagNode->name = '@' . $importedName->name;
return $spacelessPhpDocTagNode;

View File

@ -14,10 +14,6 @@ use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Symplify\SmartFileSystem\SmartFileInfo;
final class UseNodesToAddCollector implements \Rector\PostRector\Contract\Collector\NodeCollectorInterface
{
/**
* @var string[][]
*/
private $removedShortUsesInFilePath = [];
/**
* @var array<string, FullyQualifiedObjectType[]>
*/
@ -57,34 +53,15 @@ final class UseNodesToAddCollector implements \Rector\PostRector\Contract\Collec
$smartFileInfo = $file->getSmartFileInfo();
$this->functionUseImportTypesInFilePath[$smartFileInfo->getRealPath()][] = $fullyQualifiedObjectType;
}
/**
* @param \PhpParser\Node $node
* @param string $shortUse
*/
public function removeShortUse($node, $shortUse) : void
{
$file = $this->currentFileProvider->getFile();
if (!$file instanceof \Rector\Core\ValueObject\Application\File) {
return;
}
$smartFileInfo = $file->getSmartFileInfo();
$this->removedShortUsesInFilePath[$smartFileInfo->getRealPath()][] = $shortUse;
}
/**
* @param \Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo
*/
public function clear($smartFileInfo) : void
{
// clear applied imports, so isActive() doesn't return any false positives
unset($this->useImportTypesInFilePath[$smartFileInfo->getRealPath()], $this->functionUseImportTypesInFilePath[$smartFileInfo->getRealPath()]);
}
/**
* @return AliasedObjectType[]|FullyQualifiedObjectType[]
* @param \Rector\Core\ValueObject\Application\File $file
* @param \PhpParser\Node $node
*/
public function getUseImportTypesByNode($node) : array
public function getUseImportTypesByNode($file, $node) : array
{
$filePath = $this->getRealPathFromNode();
$fileInfo = $file->getSmartFileInfo();
$filePath = $fileInfo->getRealPath();
$objectTypes = $this->useImportTypesInFilePath[$filePath] ?? [];
/** @var Use_[] $useNodes */
$useNodes = (array) $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::USE_NODES);
@ -100,12 +77,13 @@ final class UseNodesToAddCollector implements \Rector\PostRector\Contract\Collec
return $objectTypes;
}
/**
* @param \Rector\Core\ValueObject\Application\File $file
* @param \PhpParser\Node $node
* @param \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType
*/
public function hasImport($node, $fullyQualifiedObjectType) : bool
public function hasImport($file, $node, $fullyQualifiedObjectType) : bool
{
$useImports = $this->getUseImportTypesByNode($node);
$useImports = $this->getUseImportTypesByNode($file, $node);
foreach ($useImports as $useImport) {
if ($useImport->equals($fullyQualifiedObjectType)) {
return \true;
@ -114,17 +92,15 @@ final class UseNodesToAddCollector implements \Rector\PostRector\Contract\Collec
return \false;
}
/**
* @param \PhpParser\Node $node
* @param \Rector\Core\ValueObject\Application\File $file
* @param \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType
*/
public function isShortImported($node, $fullyQualifiedObjectType) : bool
public function isShortImported($file, $fullyQualifiedObjectType) : bool
{
$filePath = $this->getRealPathFromNode();
if ($filePath === null) {
return \false;
}
$fileInfo = $file->getSmartFileInfo();
$filePath = $fileInfo->getRealPath();
$shortName = $fullyQualifiedObjectType->getShortName();
if ($this->isShortClassImported($filePath, $shortName)) {
if ($this->isShortClassImported($file, $shortName)) {
return \true;
}
$fileFunctionUseImportTypes = $this->functionUseImportTypesInFilePath[$filePath] ?? [];
@ -136,12 +112,13 @@ final class UseNodesToAddCollector implements \Rector\PostRector\Contract\Collec
return \false;
}
/**
* @param \PhpParser\Node $node
* @param \Rector\Core\ValueObject\Application\File $file
* @param \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType
*/
public function isImportShortable($node, $fullyQualifiedObjectType) : bool
public function isImportShortable($file, $fullyQualifiedObjectType) : bool
{
$filePath = $this->getRealPathFromNode();
$fileInfo = $file->getSmartFileInfo();
$filePath = $fileInfo->getRealPath();
$fileUseImportTypes = $this->useImportTypesInFilePath[$filePath] ?? [];
foreach ($fileUseImportTypes as $fileUseImportType) {
if ($fullyQualifiedObjectType->equals($fileUseImportType)) {
@ -172,26 +149,11 @@ final class UseNodesToAddCollector implements \Rector\PostRector\Contract\Collec
{
return $this->functionUseImportTypesInFilePath[$smartFileInfo->getRealPath()] ?? [];
}
/**
* @return string[]
* @param \Symplify\SmartFileSystem\SmartFileInfo $smartFileInfo
*/
public function getShortUsesByFileInfo($smartFileInfo) : array
private function isShortClassImported(\Rector\Core\ValueObject\Application\File $file, string $shortName) : bool
{
return $this->removedShortUsesInFilePath[$smartFileInfo->getRealPath()] ?? [];
}
private function getRealPathFromNode() : ?string
{
$file = $this->currentFileProvider->getFile();
if (!$file instanceof \Rector\Core\ValueObject\Application\File) {
return null;
}
$smartFileInfo = $file->getSmartFileInfo();
return $smartFileInfo->getRealPath();
}
private function isShortClassImported(string $filePath, string $shortName) : bool
{
$fileUseImports = $this->useImportTypesInFilePath[$filePath] ?? [];
$fileInfo = $file->getSmartFileInfo();
$realPath = $fileInfo->getRealPath();
$fileUseImports = $this->useImportTypesInFilePath[$realPath] ?? [];
foreach ($fileUseImports as $fileUseImport) {
if ($fileUseImport->getShortName() === $shortName) {
return \true;

View File

@ -117,18 +117,25 @@ CODE_SAMPLE
// @todo test if old stmts or new stmts! or both? :)
/** @var Use_[] $currentUses */
$currentUses = $this->betterNodeFinder->findInstanceOf($file->getNewStmts(), \PhpParser\Node\Stmt\Use_::class);
if (\substr_count($name->toCodeString(), '\\') <= 1) {
return $this->nameImporter->importName($name, $currentUses);
}
if (!$this->classNameImportSkipper->isFoundInUse($name, $currentUses)) {
return $this->nameImporter->importName($name, $currentUses);
}
if ($this->classNameImportSkipper->isAlreadyImported($name, $currentUses)) {
return $this->nameImporter->importName($name, $currentUses);
}
if ($this->reflectionProvider->hasFunction(new \PhpParser\Node\Name($name->getLast()), null)) {
return $this->nameImporter->importName($name, $currentUses);
if ($this->shouldImportName($name, $file, $currentUses)) {
return $this->nameImporter->importName($name, $file, $currentUses);
}
return null;
}
/**
* @param Use_[] $currentUses
*/
private function shouldImportName(\PhpParser\Node\Name $name, \Rector\Core\ValueObject\Application\File $file, array $currentUses) : bool
{
if (\substr_count($name->toCodeString(), '\\') <= 1) {
return \true;
}
if (!$this->classNameImportSkipper->isFoundInUse($name, $currentUses)) {
return \true;
}
if ($this->classNameImportSkipper->isAlreadyImported($name, $currentUses)) {
return \true;
}
return $this->reflectionProvider->hasFunction(new \PhpParser\Node\Name($name->getLast()), null);
}
}

View File

@ -70,20 +70,18 @@ final class UseAddingPostRector extends \Rector\PostRector\Rector\AbstractPostRe
$smartFileInfo = $file->getSmartFileInfo();
$useImportTypes = $this->useNodesToAddCollector->getObjectImportsByFileInfo($smartFileInfo);
$functionUseImportTypes = $this->useNodesToAddCollector->getFunctionImportsByFileInfo($smartFileInfo);
$removedShortUses = $this->useNodesToAddCollector->getShortUsesByFileInfo($smartFileInfo);
$oldToNewClasses = $this->renamedClassesDataCollector->getOldToNewClasses();
// nothing to import or remove
if ($useImportTypes === [] && $functionUseImportTypes === [] && $removedShortUses === [] && $oldToNewClasses === []) {
if ($useImportTypes === [] && $functionUseImportTypes === [] && $oldToNewClasses === []) {
return $nodes;
}
/** @var FullyQualifiedObjectType[] $useImportTypes */
$useImportTypes = $this->typeFactory->uniquateTypes($useImportTypes);
$this->useNodesToAddCollector->clear($smartFileInfo);
// A. has namespace? add under it
$namespace = $this->betterNodeFinder->findFirstInstanceOf($nodes, \PhpParser\Node\Stmt\Namespace_::class);
if ($namespace instanceof \PhpParser\Node\Stmt\Namespace_) {
// first clean
$this->useImportsRemover->removeImportsFromNamespace($namespace, $removedShortUses);
//$this->useImportsRemover->removeImportsFromNamespace($namespace, $removedShortUses);
// then add, to prevent adding + removing false positive of same short use
$this->useImportsAdder->addImportsToNamespace($namespace, $useImportTypes, $functionUseImportTypes);
return $nodes;
@ -92,7 +90,7 @@ final class UseAddingPostRector extends \Rector\PostRector\Rector\AbstractPostRe
if ($firstNode instanceof \Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace) {
$nodes = $firstNode->stmts;
}
$removedShortUses = \array_merge($removedShortUses, $this->renamedClassesDataCollector->getOldClasses());
$removedShortUses = $this->renamedClassesDataCollector->getOldClasses();
// B. no namespace? add in the top
// first clean
$nodes = $this->useImportsRemover->removeImportsFromStmts($nodes, $removedShortUses);

View File

@ -45,9 +45,11 @@ final class FullyQualifiedObjectType extends \PHPStan\Type\ObjectType
public function getFunctionUseNode() : \PhpParser\Node\Stmt\Use_
{
$name = new \PhpParser\Node\Name($this->getClassName());
$useUse = new \PhpParser\Node\Stmt\UseUse($name, null, \PhpParser\Node\Stmt\Use_::TYPE_FUNCTION);
$useUse = new \PhpParser\Node\Stmt\UseUse($name, null);
$name->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE, $useUse);
return new \PhpParser\Node\Stmt\Use_([$useUse]);
$use = new \PhpParser\Node\Stmt\Use_([$useUse]);
$use->type = \PhpParser\Node\Stmt\Use_::TYPE_FUNCTION;
return $use;
}
public function getShortNameLowered() : string
{

View File

@ -11,6 +11,7 @@ use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Use_;
use PHPStan\Type\ObjectType;
use Rector\CodingStyle\ClassNameImport\UsedImportsResolver;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
final class UseImportsAdder
@ -19,9 +20,14 @@ final class UseImportsAdder
* @var \Rector\CodingStyle\ClassNameImport\UsedImportsResolver
*/
private $usedImportsResolver;
public function __construct(\Rector\CodingStyle\ClassNameImport\UsedImportsResolver $usedImportsResolver)
/**
* @var \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory
*/
private $typeFactory;
public function __construct(\Rector\CodingStyle\ClassNameImport\UsedImportsResolver $usedImportsResolver, \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory $typeFactory)
{
$this->usedImportsResolver = $usedImportsResolver;
$this->typeFactory = $typeFactory;
}
/**
* @param Stmt[] $stmts

View File

@ -6,6 +6,7 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
use PhpParser\Node;
use Rector\CodingStyle\ClassNameImport\AliasUsesResolver;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Core\ValueObject\Application\File;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
/**
* Prevents adding:
@ -27,10 +28,11 @@ final class AliasClassNameImportSkipVoter implements \Rector\CodingStyle\Contrac
$this->aliasUsesResolver = $aliasUsesResolver;
}
/**
* @param \Rector\Core\ValueObject\Application\File $file
* @param \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType
* @param \PhpParser\Node $node
*/
public function shouldSkip($fullyQualifiedObjectType, $node) : bool
public function shouldSkip($file, $fullyQualifiedObjectType, $node) : bool
{
$aliasedUses = $this->aliasUsesResolver->resolveForNode($node);
foreach ($aliasedUses as $aliasedUse) {

View File

@ -6,6 +6,7 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
use PhpParser\Node;
use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Core\ValueObject\Application\File;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
/**
* Prevents adding:
@ -27,10 +28,11 @@ final class ClassLikeNameClassNameImportSkipVoter implements \Rector\CodingStyle
$this->shortNameResolver = $shortNameResolver;
}
/**
* @param \Rector\Core\ValueObject\Application\File $file
* @param \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType
* @param \PhpParser\Node $node
*/
public function shouldSkip($fullyQualifiedObjectType, $node) : bool
public function shouldSkip($file, $fullyQualifiedObjectType, $node) : bool
{
$classLikeNames = $this->shortNameResolver->resolveShortClassLikeNamesForNode($node);
foreach ($classLikeNames as $classLikeName) {

View File

@ -6,7 +6,7 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
use PhpParser\Node;
use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\ValueObject\Application\File;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
/**
* Prevents adding:
@ -23,23 +23,18 @@ final class FullyQualifiedNameClassNameImportSkipVoter implements \Rector\Coding
* @var \Rector\CodingStyle\ClassNameImport\ShortNameResolver
*/
private $shortNameResolver;
/**
* @var \Rector\Core\Provider\CurrentFileProvider
*/
private $currentFileProvider;
public function __construct(\Rector\CodingStyle\ClassNameImport\ShortNameResolver $shortNameResolver, \Rector\Core\Provider\CurrentFileProvider $currentFileProvider)
public function __construct(\Rector\CodingStyle\ClassNameImport\ShortNameResolver $shortNameResolver)
{
$this->shortNameResolver = $shortNameResolver;
$this->currentFileProvider = $currentFileProvider;
}
/**
* @param \Rector\Core\ValueObject\Application\File $file
* @param \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType
* @param \PhpParser\Node $node
*/
public function shouldSkip($fullyQualifiedObjectType, $node) : bool
public function shouldSkip($file, $fullyQualifiedObjectType, $node) : bool
{
// "new X" or "X::static()"
$file = $this->currentFileProvider->getFile();
$shortNamesToFullyQualifiedNames = $this->shortNameResolver->resolveForNode($file);
foreach ($shortNamesToFullyQualifiedNames as $shortName => $fullyQualifiedName) {
$shortNameLowered = \strtolower($shortName);

View File

@ -6,6 +6,7 @@ namespace Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter;
use PhpParser\Node;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Core\Configuration\RenamedClassesDataCollector;
use Rector\Core\ValueObject\Application\File;
use Rector\PostRector\Collector\UseNodesToAddCollector;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
/**
@ -31,12 +32,13 @@ final class UsesClassNameImportSkipVoter implements \Rector\CodingStyle\Contract
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
}
/**
* @param \Rector\Core\ValueObject\Application\File $file
* @param \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType
* @param \PhpParser\Node $node
*/
public function shouldSkip($fullyQualifiedObjectType, $node) : bool
public function shouldSkip($file, $fullyQualifiedObjectType, $node) : bool
{
$useImportTypes = $this->useNodesToAddCollector->getUseImportTypesByNode($node);
$useImportTypes = $this->useNodesToAddCollector->getUseImportTypesByNode($file, $node);
foreach ($useImportTypes as $useImportType) {
// if the class is renamed, the use import is no longer blocker
if ($this->renamedClassesDataCollector->hasOldClass($useImportType->getClassName())) {

View File

@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\Stmt\UseUse;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Core\Configuration\RenamedClassesDataCollector;
use Rector\Core\ValueObject\Application\File;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
final class ClassNameImportSkipper
{
@ -28,10 +29,10 @@ final class ClassNameImportSkipper
$this->classNameImportSkipVoters = $classNameImportSkipVoters;
$this->renamedClassesDataCollector = $renamedClassesDataCollector;
}
public function shouldSkipNameForFullyQualifiedObjectType(\PhpParser\Node $node, \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType) : bool
public function shouldSkipNameForFullyQualifiedObjectType(\Rector\Core\ValueObject\Application\File $file, \PhpParser\Node $node, \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType) : bool
{
foreach ($this->classNameImportSkipVoters as $classNameImportSkipVoter) {
if ($classNameImportSkipVoter->shouldSkip($fullyQualifiedObjectType, $node)) {
if ($classNameImportSkipVoter->shouldSkip($file, $fullyQualifiedObjectType, $node)) {
return \true;
}
}

View File

@ -4,12 +4,14 @@ declare (strict_types=1);
namespace Rector\CodingStyle\Contract\ClassNameImport;
use PhpParser\Node;
use Rector\Core\ValueObject\Application\File;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
interface ClassNameImportSkipVoterInterface
{
/**
* @param \Rector\Core\ValueObject\Application\File $file
* @param \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType
* @param \PhpParser\Node $node
*/
public function shouldSkip($fullyQualifiedObjectType, $node) : bool;
public function shouldSkip($file, $fullyQualifiedObjectType, $node) : bool;
}

View File

@ -14,6 +14,7 @@ use PHPStan\Reflection\ReflectionProvider;
use Rector\CodingStyle\ClassNameImport\AliasUsesResolver;
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\Application\File;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PostRector\Collector\UseNodesToAddCollector;
@ -67,7 +68,7 @@ final class NameImporter
/**
* @param Use_[] $uses
*/
public function importName(\PhpParser\Node\Name $name, array $uses) : ?\PhpParser\Node\Name
public function importName(\PhpParser\Node\Name $name, \Rector\Core\ValueObject\Application\File $file, array $uses) : ?\PhpParser\Node\Name
{
if ($this->shouldSkipName($name)) {
return null;
@ -80,7 +81,7 @@ final class NameImporter
return null;
}
$this->aliasedUses = $this->aliasUsesResolver->resolveForNode($name);
return $this->importNameAndCollectNewUseStatement($name, $staticType);
return $this->importNameAndCollectNewUseStatement($file, $name, $staticType);
}
private function shouldSkipName(\PhpParser\Node\Name $name) : bool
{
@ -109,19 +110,19 @@ final class NameImporter
}
return \false;
}
private function importNameAndCollectNewUseStatement(\PhpParser\Node\Name $name, \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType) : ?\PhpParser\Node\Name
private function importNameAndCollectNewUseStatement(\Rector\Core\ValueObject\Application\File $file, \PhpParser\Node\Name $name, \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType) : ?\PhpParser\Node\Name
{
// the same end is already imported → skip
if ($this->classNameImportSkipper->shouldSkipNameForFullyQualifiedObjectType($name, $fullyQualifiedObjectType)) {
if ($this->classNameImportSkipper->shouldSkipNameForFullyQualifiedObjectType($file, $name, $fullyQualifiedObjectType)) {
return null;
}
if ($this->useNodesToAddCollector->isShortImported($name, $fullyQualifiedObjectType)) {
if ($this->useNodesToAddCollector->isImportShortable($name, $fullyQualifiedObjectType)) {
if ($this->useNodesToAddCollector->isShortImported($file, $fullyQualifiedObjectType)) {
if ($this->useNodesToAddCollector->isImportShortable($file, $fullyQualifiedObjectType)) {
return $fullyQualifiedObjectType->getShortNameNode();
}
return null;
}
$this->addUseImport($name, $fullyQualifiedObjectType);
$this->addUseImport($file, $name, $fullyQualifiedObjectType);
// possibly aliased
foreach ($this->aliasedUses as $aliasedUse) {
if ($fullyQualifiedObjectType->getClassName() === $aliasedUse) {
@ -159,9 +160,9 @@ final class NameImporter
}
return \false;
}
private function addUseImport(\PhpParser\Node\Name $name, \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType) : void
private function addUseImport(\Rector\Core\ValueObject\Application\File $file, \PhpParser\Node\Name $name, \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType $fullyQualifiedObjectType) : void
{
if ($this->useNodesToAddCollector->hasImport($name, $fullyQualifiedObjectType)) {
if ($this->useNodesToAddCollector->hasImport($file, $name, $fullyQualifiedObjectType)) {
return;
}
$parentNode = $name->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '242fa166104396ce6835c07b69eef3cd0936c653';
public const PACKAGE_VERSION = '24a32dfefb21f925bbf48ad58b3d834d7988ca40';
/**
* @var string
*/
public const RELEASE_DATE = '2021-07-21 11:27:17';
public const RELEASE_DATE = '2021-07-21 15:37:24';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210721\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a::getLoader();
return ComposerAutoloaderInit6360f57b832da85cfc9162265ec2d310::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a
class ComposerAutoloaderInit6360f57b832da85cfc9162265ec2d310
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit6360f57b832da85cfc9162265ec2d310', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit6360f57b832da85cfc9162265ec2d310', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit38f8337ccf82794415d0e1cc2bb4c25a::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit6360f57b832da85cfc9162265ec2d310::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit38f8337ccf82794415d0e1cc2bb4c25a::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit6360f57b832da85cfc9162265ec2d310::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire38f8337ccf82794415d0e1cc2bb4c25a($fileIdentifier, $file);
composerRequire6360f57b832da85cfc9162265ec2d310($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire38f8337ccf82794415d0e1cc2bb4c25a($fileIdentifier, $file)
function composerRequire6360f57b832da85cfc9162265ec2d310($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit38f8337ccf82794415d0e1cc2bb4c25a
class ComposerStaticInit6360f57b832da85cfc9162265ec2d310
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3844,9 +3844,9 @@ class ComposerStaticInit38f8337ccf82794415d0e1cc2bb4c25a
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit38f8337ccf82794415d0e1cc2bb4c25a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit38f8337ccf82794415d0e1cc2bb4c25a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit38f8337ccf82794415d0e1cc2bb4c25a::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit6360f57b832da85cfc9162265ec2d310::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6360f57b832da85cfc9162265ec2d310::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6360f57b832da85cfc9162265ec2d310::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1779,12 +1779,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/symfony\/console.git",
"reference": "c7fa320bd77e22743a34b0f03933afbba75dfbb9"
"reference": "300db7fbe658482a65db9d35ede3cb6de01d8af4"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symfony\/console\/zipball\/c7fa320bd77e22743a34b0f03933afbba75dfbb9",
"reference": "c7fa320bd77e22743a34b0f03933afbba75dfbb9",
"url": "https:\/\/api.github.com\/repos\/symfony\/console\/zipball\/300db7fbe658482a65db9d35ede3cb6de01d8af4",
"reference": "300db7fbe658482a65db9d35ede3cb6de01d8af4",
"shasum": ""
},
"require": {
@ -1792,7 +1792,7 @@
"symfony\/deprecation-contracts": "^2.1",
"symfony\/polyfill-mbstring": "~1.0",
"symfony\/polyfill-php73": "^1.8",
"symfony\/polyfill-php80": "^1.15",
"symfony\/polyfill-php80": "^1.16",
"symfony\/service-contracts": "^1.1|^2",
"symfony\/string": "^5.1"
},
@ -1822,7 +1822,7 @@
"symfony\/lock": "",
"symfony\/process": ""
},
"time": "2021-07-21T09:14:51+00:00",
"time": "2021-07-21T12:40:44+00:00",
"default-branch": true,
"type": "library",
"installation-source": "dist",
@ -1882,19 +1882,19 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/symfony\/dependency-injection.git",
"reference": "a917d7cf73f5ada5641728779214c477bd5238c4"
"reference": "6b12d5bcd1e2f1cc9507cea6181787d642ec46b5"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symfony\/dependency-injection\/zipball\/a917d7cf73f5ada5641728779214c477bd5238c4",
"reference": "a917d7cf73f5ada5641728779214c477bd5238c4",
"url": "https:\/\/api.github.com\/repos\/symfony\/dependency-injection\/zipball\/6b12d5bcd1e2f1cc9507cea6181787d642ec46b5",
"reference": "6b12d5bcd1e2f1cc9507cea6181787d642ec46b5",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"psr\/container": "^1.1.1",
"symfony\/deprecation-contracts": "^2.1",
"symfony\/polyfill-php80": "^1.15",
"symfony\/polyfill-php80": "^1.16",
"symfony\/service-contracts": "^1.1.6|^2"
},
"conflict": {
@ -1920,7 +1920,7 @@
"symfony\/proxy-manager-bridge": "Generate service proxies to lazy load them",
"symfony\/yaml": ""
},
"time": "2021-07-18T16:30:56+00:00",
"time": "2021-07-21T12:40:44+00:00",
"default-branch": true,
"type": "library",
"installation-source": "dist",

File diff suppressed because one or more lines are too long

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20210721\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a', false) && !interface_exists('ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a', false) && !trait_exists('ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a', false)) {
spl_autoload_call('RectorPrefix20210721\ComposerAutoloaderInit38f8337ccf82794415d0e1cc2bb4c25a');
if (!class_exists('ComposerAutoloaderInit6360f57b832da85cfc9162265ec2d310', false) && !interface_exists('ComposerAutoloaderInit6360f57b832da85cfc9162265ec2d310', false) && !trait_exists('ComposerAutoloaderInit6360f57b832da85cfc9162265ec2d310', false)) {
spl_autoload_call('RectorPrefix20210721\ComposerAutoloaderInit6360f57b832da85cfc9162265ec2d310');
}
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
spl_autoload_call('RectorPrefix20210721\Doctrine\Inflector\Inflector');
@ -3308,9 +3308,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210721\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire38f8337ccf82794415d0e1cc2bb4c25a')) {
function composerRequire38f8337ccf82794415d0e1cc2bb4c25a() {
return \RectorPrefix20210721\composerRequire38f8337ccf82794415d0e1cc2bb4c25a(...func_get_args());
if (!function_exists('composerRequire6360f57b832da85cfc9162265ec2d310')) {
function composerRequire6360f57b832da85cfc9162265ec2d310() {
return \RectorPrefix20210721\composerRequire6360f57b832da85cfc9162265ec2d310(...func_get_args());
}
}
if (!function_exists('parseArgs')) {

View File

@ -724,7 +724,7 @@ class Application implements \RectorPrefix20210721\Symfony\Contracts\Service\Res
} else {
$len = 0;
}
if (\false !== \strpos($message, "@anonymous\0")) {
if (\strpos($message, "@anonymous\0") !== \false) {
$message = \preg_replace_callback('/[a-zA-Z_\\x7f-\\xff][\\\\a-zA-Z0-9_\\x7f-\\xff]*+@anonymous\\x00.*?\\.php(?:0x?|:[0-9]++\\$)[0-9a-fA-F]++/', function ($m) {
return \class_exists($m[0], \false) ? ((\get_parent_class($m[0]) ?: \key(\class_implements($m[0]))) ?: 'class') . '@anonymous' : $m[0];
}, $message);
@ -982,7 +982,7 @@ class Application implements \RectorPrefix20210721\Symfony\Contracts\Service\Res
continue;
}
$lev = \levenshtein($subname, $parts[$i]);
if ($lev <= \strlen($subname) / 3 || '' !== $subname && \false !== \strpos($parts[$i], $subname)) {
if ($lev <= \strlen($subname) / 3 || '' !== $subname && \strpos($parts[$i], $subname) !== \false) {
$alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
} elseif ($exists) {
$alternatives[$collectionName] += $threshold;
@ -991,7 +991,7 @@ class Application implements \RectorPrefix20210721\Symfony\Contracts\Service\Res
}
foreach ($collection as $item) {
$lev = \levenshtein($name, $item);
if ($lev <= \strlen($name) / 3 || \false !== \strpos($item, $name)) {
if ($lev <= \strlen($name) / 3 || \strpos($item, $name) !== \false) {
$alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
}
}

View File

@ -586,7 +586,7 @@ class Command
*/
public function addUsage($usage)
{
if (0 !== \strpos($usage, $this->name)) {
if (\strncmp($usage, $this->name, \strlen($this->name)) !== 0) {
$usage = \sprintf('%s %s', $this->name, $usage);
}
$this->usages[] = $usage;

View File

@ -48,7 +48,7 @@ class OutputFormatter implements \RectorPrefix20210721\Symfony\Component\Console
*/
public static function escapeTrailingBackslash($text) : string
{
if ('\\' === \substr($text, -1)) {
if (\substr_compare($text, '\\', -\strlen('\\')) === 0) {
$len = \strlen($text);
$text = \rtrim($text, '\\');
$text = \str_replace("\0", '', $text);
@ -163,7 +163,7 @@ class OutputFormatter implements \RectorPrefix20210721\Symfony\Component\Console
}
}
$output .= $this->applyCurrentStyle(\substr($message, $offset), $output, $width, $currentLineLength);
if (\false !== \strpos($output, "\0")) {
if (\strpos($output, "\0") !== \false) {
return \strtr($output, ["\0" => '\\', '\\<' => '<']);
}
return \str_replace('\\<', '<', $output);

View File

@ -265,7 +265,7 @@ class QuestionHelper extends \RectorPrefix20210721\Symfony\Component\Console\Hel
$fullChoice .= $remainingCharacters;
$i = \false === ($encoding = \mb_detect_encoding($fullChoice, null, \true)) ? \strlen($fullChoice) : \mb_strlen($fullChoice, $encoding);
$matches = \array_filter($autocomplete($ret), function ($match) use($ret) {
return '' === $ret || 0 === \strpos($match, $ret);
return '' === $ret || \strncmp($match, $ret, \strlen($ret)) === 0;
});
$numMatches = \count($matches);
$ofs = -1;
@ -293,7 +293,7 @@ class QuestionHelper extends \RectorPrefix20210721\Symfony\Component\Console\Hel
$ofs = 0;
foreach ($autocomplete($ret) as $value) {
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
if (0 === \strpos($value, $tempRet)) {
if (\strncmp($value, $tempRet, \strlen($tempRet)) === 0) {
$matches[$numMatches++] = $value;
}
}
@ -314,7 +314,7 @@ class QuestionHelper extends \RectorPrefix20210721\Symfony\Component\Console\Hel
private function mostRecentlyEnteredValue(string $entered) : string
{
// Determine the most recent value that the user entered
if (\false === \strpos($entered, ',')) {
if (\strpos($entered, ',') === \false) {
return $entered;
}
$choices = \explode(',', $entered);

View File

@ -335,6 +335,7 @@ class Table
$this->calculateColumnsWidth($rows);
$isHeader = !$this->horizontal;
$isFirstRow = $this->horizontal;
$hasTitle = (bool) $this->headerTitle;
foreach ($rows as $row) {
if ($divider === $row) {
$isHeader = \false;
@ -349,12 +350,9 @@ class Table
continue;
}
if ($isHeader || $isFirstRow) {
if ($isFirstRow) {
$this->renderRowSeparator(self::SEPARATOR_TOP_BOTTOM);
$isFirstRow = \false;
} else {
$this->renderRowSeparator(self::SEPARATOR_TOP, $this->headerTitle, $this->style->getHeaderTitleFormat());
}
$this->renderRowSeparator($isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM, $hasTitle ? $this->headerTitle : null, $hasTitle ? $this->style->getHeaderTitleFormat() : null);
$isFirstRow = \false;
$hasTitle = \false;
}
if ($this->horizontal) {
$this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat());

View File

@ -67,7 +67,7 @@ class ArgvInput extends \RectorPrefix20210721\Symfony\Component\Console\Input\In
$this->parseArgument($token);
} elseif ($parseOptions && '--' == $token) {
$parseOptions = \false;
} elseif ($parseOptions && 0 === \strpos($token, '--')) {
} elseif ($parseOptions && \strncmp($token, '--', \strlen('--')) === 0) {
$this->parseLongOption($token);
} elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
$this->parseShortOption($token);
@ -235,7 +235,7 @@ class ArgvInput extends \RectorPrefix20210721\Symfony\Component\Console\Input\In
$isOption = \false;
foreach ($this->tokens as $i => $token) {
if ($token && '-' === $token[0]) {
if (\false !== \strpos($token, '=') || !isset($this->tokens[$i + 1])) {
if (\strpos($token, '=') !== \false || !isset($this->tokens[$i + 1])) {
continue;
}
// If it's a long option, consider that everything after "--" is the option name.
@ -271,8 +271,8 @@ class ArgvInput extends \RectorPrefix20210721\Symfony\Component\Console\Input\In
// Options with values:
// For long options, test for '--option=' at beginning
// For short options, test for '-o' at beginning
$leading = 0 === \strpos($value, '--') ? $value . '=' : $value;
if ($token === $value || '' !== $leading && 0 === \strpos($token, $leading)) {
$leading = \strncmp($value, '--', \strlen('--')) === 0 ? $value . '=' : $value;
if ($token === $value || '' !== $leading && \strncmp($token, $leading, \strlen($leading)) === 0) {
return \true;
}
}
@ -299,8 +299,8 @@ class ArgvInput extends \RectorPrefix20210721\Symfony\Component\Console\Input\In
// Options with values:
// For long options, test for '--option=' at beginning
// For short options, test for '-o' at beginning
$leading = 0 === \strpos($value, '--') ? $value . '=' : $value;
if ('' !== $leading && 0 === \strpos($token, $leading)) {
$leading = \strncmp($value, '--', \strlen('--')) === 0 ? $value . '=' : $value;
if ('' !== $leading && \strncmp($token, $leading, \strlen($leading)) === 0) {
return \substr($token, \strlen($leading));
}
}

View File

@ -116,9 +116,9 @@ class ArrayInput extends \RectorPrefix20210721\Symfony\Component\Console\Input\I
if ('--' === $key) {
return;
}
if (0 === \strpos($key, '--')) {
if (\strncmp($key, '--', \strlen('--')) === 0) {
$this->addLongOption(\substr($key, 2), $value);
} elseif (0 === \strpos($key, '-')) {
} elseif (\strncmp($key, '-', \strlen('-')) === 0) {
$this->addShortOption(\substr($key, 1), $value);
} else {
$this->addArgument($key, $value);

View File

@ -53,7 +53,7 @@ class InputOption
*/
public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
{
if (0 === \strpos($name, '--')) {
if (\strncmp($name, '--', \strlen('--')) === 0) {
$name = \substr($name, 2);
}
if (empty($name)) {

View File

@ -77,7 +77,7 @@ class ConsoleLogger extends \RectorPrefix20210721\Psr\Log\AbstractLogger
*/
private function interpolate(string $message, array $context) : string
{
if (\false === \strpos($message, '{')) {
if (\strpos($message, '{') === \false) {
return $message;
}
$replacements = [];

View File

@ -383,7 +383,7 @@ class SymfonyStyle extends \RectorPrefix20210721\Symfony\Component\Console\Style
{
$fetched = $this->bufferedOutput->fetch();
//Prepend new line if last char isn't EOL:
if ("\n" !== \substr($fetched, -1)) {
if (\substr_compare($fetched, "\n", -\strlen("\n")) !== 0) {
$this->newLine();
}
}

View File

@ -25,7 +25,7 @@
"symfony\/deprecation-contracts": "^2.1",
"symfony\/polyfill-mbstring": "~1.0",
"symfony\/polyfill-php73": "^1.8",
"symfony\/polyfill-php80": "^1.15",
"symfony\/polyfill-php80": "^1.16",
"symfony\/service-contracts": "^1.1|^2",
"symfony\/string": "^5.1"
},

View File

@ -97,7 +97,7 @@ class Alias
if (\preg_match('#[\\r\\n]|\\*/#', $message)) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('Invalid characters found in deprecation template.');
}
if (\false === \strpos($message, '%alias_id%')) {
if (\strpos($message, '%alias_id%') === \false) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('The deprecation template must contain the "%alias_id%" placeholder.');
}
}

View File

@ -85,7 +85,7 @@ class ChildDefinition extends \RectorPrefix20210721\Symfony\Component\Dependency
{
if (\is_int($index)) {
$this->arguments['index_' . $index] = $value;
} elseif (0 === \strpos($index, '$')) {
} elseif (\strncmp($index, '$', \strlen('$')) === 0) {
$this->arguments[$index] = $value;
} else {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('The argument must be an existing index or the name of a constructor\'s parameter.');

View File

@ -274,7 +274,7 @@ class AutowirePass extends \RectorPrefix20210721\Symfony\Component\DependencyInj
}
if ($this->container->has($name) && !$this->container->findDefinition($name)->isAbstract()) {
foreach ($this->container->getAliases() as $id => $alias) {
if ($name === (string) $alias && 0 === \strpos($id, $type . ' $')) {
if ($name === (string) $alias && \strncmp($id, $type . ' $', \strlen($type . ' $')) === 0) {
return new \RectorPrefix20210721\Symfony\Component\DependencyInjection\TypedReference($name, $type, $reference->getInvalidBehavior());
}
}

View File

@ -47,7 +47,7 @@ class CheckDefinitionValidityPass implements \RectorPrefix20210721\Symfony\Compo
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id));
}
if (\class_exists($id) || \interface_exists($id, \false)) {
if (0 === \strpos($id, '\\') && 1 < \substr_count($id, '\\')) {
if (\strncmp($id, '\\', \strlen('\\')) === 0 && 1 < \substr_count($id, '\\')) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "%s" to get rid of this error.', $id, \substr($id, 1)));
}
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('The definition for "%s" has no class attribute, and appears to reference a class or interface in the global namespace. Leaving out the "class" attribute is only allowed for namespaced classes. Please specify the class attribute explicitly to get rid of this error.', $id));

View File

@ -180,7 +180,7 @@ final class CheckTypeDeclarationsPass extends \RectorPrefix20210721\Symfony\Comp
if ('%' === ($value[0] ?? '') && \preg_match('/^%([^%]+)%$/', $value, $match)) {
$value = $this->container->getParameter(\substr($value, 1, -1));
}
if ($envPlaceholderUniquePrefix && \is_string($value) && \false !== \strpos($value, 'env_')) {
if ($envPlaceholderUniquePrefix && \is_string($value) && \strpos($value, 'env_') !== \false) {
// If the value is an env placeholder that is either mixed with a string or with another env placeholder, then its resolved value will always be a string, so we don't need to resolve it.
// We don't need to change the value because it is already a string.
if ('' === \preg_replace('/' . $envPlaceholderUniquePrefix . '_\\w+_[a-f0-9]{32}/U', '', $value, -1, $c) && 1 === $c) {

View File

@ -62,7 +62,7 @@ class Compiler
*/
public function log($pass, $message)
{
if (\false !== \strpos($message, "\n")) {
if (\strpos($message, "\n") !== \false) {
$message = \str_replace("\n", "\n" . \get_class($pass) . ': ', \trim($message));
}
$this->log[] = \get_class($pass) . ': ' . $message;

View File

@ -194,7 +194,7 @@ class MergeExtensionConfigurationContainerBuilder extends \RectorPrefix20210721\
return parent::resolveEnvPlaceholders($value, $format, $usedEnvs);
}
foreach ($bag->getEnvPlaceholders() as $env => $placeholders) {
if (\false === \strpos($env, ':')) {
if (\strpos($env, ':') === \false) {
continue;
}
foreach ($placeholders as $placeholder) {

View File

@ -94,7 +94,7 @@ class RegisterServiceSubscribersPass extends \RectorPrefix20210721\Symfony\Compo
if ($name) {
if (\false !== ($i = \strpos($name, '::get'))) {
$name = \lcfirst(\substr($name, 5 + $i));
} elseif (\false !== \strpos($name, '::')) {
} elseif (\strpos($name, '::') !== \false) {
$name = null;
}
}

View File

@ -40,7 +40,7 @@ class ResolveBindingsPass extends \RectorPrefix20210721\Symfony\Component\Depend
parent::process($container);
foreach ($this->unusedBindings as [$key, $serviceId, $bindingType, $file]) {
$argumentType = $argumentName = $message = null;
if (\false !== \strpos($key, ' ')) {
if (\strpos($key, ' ') !== \false) {
[$argumentType, $argumentName] = \explode(' ', $key, 2);
} elseif ('$' === $key[0]) {
$argumentName = $key;

View File

@ -152,7 +152,7 @@ class ResolveChildDefinitionsPass extends \RectorPrefix20210721\Symfony\Componen
foreach ($definition->getArguments() as $k => $v) {
if (\is_numeric($k)) {
$def->addArgument($v);
} elseif (0 === \strpos($k, 'index_')) {
} elseif (\strncmp($k, 'index_', \strlen('index_')) === 0) {
$def->replaceArgument((int) \substr($k, \strlen('index_')), $v);
} else {
$def->setArgument($k, $v);

View File

@ -236,7 +236,7 @@ class Container implements \RectorPrefix20210721\Symfony\Component\DependencyInj
continue;
}
$lev = \levenshtein($id, $knownId);
if ($lev <= \strlen($id) / 3 || \false !== \strpos($knownId, $id)) {
if ($lev <= \strlen($id) / 3 || \strpos($knownId, $id) !== \false) {
$alternatives[] = $knownId;
}
}

View File

@ -1461,7 +1461,7 @@ class ContainerBuilder extends \RectorPrefix20210721\Symfony\Component\Dependenc
}
$path = \realpath($path) ?: $path;
foreach ($this->vendors as $vendor) {
if (0 === \strpos($path, $vendor) && \false !== \strpbrk(\substr($path, \strlen($vendor), 1), '/' . \DIRECTORY_SEPARATOR)) {
if (\strncmp($path, $vendor, \strlen($vendor)) === 0 && \false !== \strpbrk(\substr($path, \strlen($vendor), 1), '/' . \DIRECTORY_SEPARATOR)) {
$this->addResource(new \RectorPrefix20210721\Symfony\Component\Config\Resource\FileResource($vendor . '/composer/installed.json'));
return \true;
}

View File

@ -92,7 +92,7 @@ class Definition
public function setFactory($factory)
{
$this->changes['factory'] = \true;
if (\is_string($factory) && \false !== \strpos($factory, '::')) {
if (\is_string($factory) && \strpos($factory, '::') !== \false) {
$factory = \explode('::', $factory, 2);
} elseif ($factory instanceof \RectorPrefix20210721\Symfony\Component\DependencyInjection\Reference) {
$factory = [$factory, '__invoke'];
@ -656,7 +656,7 @@ class Definition
if (\preg_match('#[\\r\\n]|\\*/#', $message)) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('Invalid characters found in deprecation template.');
}
if (\false === \strpos($message, '%service_id%')) {
if (\strpos($message, '%service_id%') === \false) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('The deprecation template must contain the "%service_id%" placeholder.');
}
}
@ -705,7 +705,7 @@ class Definition
public function setConfigurator($configurator)
{
$this->changes['configurator'] = \true;
if (\is_string($configurator) && \false !== \strpos($configurator, '::')) {
if (\is_string($configurator) && \strpos($configurator, '::') !== \false) {
$configurator = \explode('::', $configurator, 2);
} elseif ($configurator instanceof \RectorPrefix20210721\Symfony\Component\DependencyInjection\Reference) {
$configurator = [$configurator, '__invoke'];

View File

@ -138,7 +138,7 @@ class PhpDumper extends \RectorPrefix20210721\Symfony\Component\DependencyInject
$this->inlineFactories = $this->asFiles && $options['inline_factories_parameter'] && $this->container->hasParameter($options['inline_factories_parameter']) && $this->container->getParameter($options['inline_factories_parameter']);
$this->inlineRequires = $options['inline_class_loader_parameter'] && ($this->container->hasParameter($options['inline_class_loader_parameter']) ? $this->container->getParameter($options['inline_class_loader_parameter']) : \PHP_VERSION_ID < 70400 || $options['debug']);
$this->serviceLocatorTag = $options['service_locator_tag'];
if (0 !== \strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) {
if (\strncmp($baseClass = $options['base_class'], '\\', \strlen('\\')) !== 0 && 'Container' !== $baseClass) {
$baseClass = \sprintf('%s\\%s', $options['namespace'] ? '\\' . $options['namespace'] : '', $baseClass);
$this->baseClass = $baseClass;
} elseif ('Container' === $baseClass) {
@ -273,7 +273,7 @@ require __DIR__.'/{$preloadedFiles}';
EOF;
foreach ($this->preload as $class) {
if (!$class || \false !== \strpos($class, '$') || \in_array($class, ['int', 'float', 'string', 'bool', 'resource', 'object', 'array', 'null', 'callable', 'iterable', 'mixed', 'void'], \true)) {
if (!$class || \strpos($class, '$') !== \false || \in_array($class, ['int', 'float', 'string', 'bool', 'resource', 'object', 'array', 'null', 'callable', 'iterable', 'mixed', 'void'], \true)) {
continue;
}
if (!(\class_exists($class, \false) || \interface_exists($class, \false) || \trait_exists($class, \false)) || (new \ReflectionClass($class))->isUserDefined()) {
@ -447,7 +447,7 @@ EOF;
return;
}
$file = $r->getFileName();
if (') : eval()\'d code' === \substr($file, -17)) {
if (\substr_compare($file, ') : eval()\'d code', -\strlen(') : eval()\'d code')) === 0) {
$file = \substr($file, 0, \strrpos($file, '(', -17));
}
if (!$file || $this->doExport($file) === ($exportedFile = $this->export($file))) {
@ -553,7 +553,7 @@ EOF;
private function addServiceInstance(string $id, \RectorPrefix20210721\Symfony\Component\DependencyInjection\Definition $definition, bool $isSimpleInstance) : string
{
$class = $this->dumpValue($definition->getClass());
if (0 === \strpos($class, "'") && \false === \strpos($class, '$') && !\preg_match('/^\'(?:\\\\{2})?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\\\{2}[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*\'$/', $class)) {
if (\strncmp($class, "'", \strlen("'")) === 0 && \strpos($class, '$') === \false && !\preg_match('/^\'(?:\\\\{2})?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\\\{2}[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*\'$/', $class)) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
}
$isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition);
@ -659,10 +659,10 @@ EOF;
}
$class = $this->dumpValue($callable[0]);
// If the class is a string we can optimize away
if (0 === \strpos($class, "'") && \false === \strpos($class, '$')) {
if (\strncmp($class, "'", \strlen("'")) === 0 && \strpos($class, '$') === \false) {
return \sprintf(" %s::%s(\$%s);\n", $this->dumpLiteralClass($class), $callable[1], $variableName);
}
if (0 === \strpos($class, 'new ')) {
if (\strncmp($class, 'new ', \strlen('new ')) === 0) {
return \sprintf(" (%s)->%s(\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
}
return \sprintf(" [%s, '%s'](\$%s);\n", $this->dumpValue($callable[0]), $callable[1], $variableName);
@ -678,7 +678,7 @@ EOF;
$return = [];
if ($class = $definition->getClass()) {
$class = $class instanceof \RectorPrefix20210721\Symfony\Component\DependencyInjection\Parameter ? '%' . $class . '%' : $this->container->resolveEnvPlaceholders($class);
$return[] = \sprintf(0 === \strpos($class, '%') ? '@return object A %1$s instance' : '@return \\%s', \ltrim($class, '\\'));
$return[] = \sprintf(\strncmp($class, '%', \strlen('%')) === 0 ? '@return object A %1$s instance' : '@return \\%s', \ltrim($class, '\\'));
} elseif ($definition->getFactory()) {
$factory = $definition->getFactory();
if (\is_string($factory)) {
@ -690,7 +690,7 @@ EOF;
}
}
if ($definition->isDeprecated()) {
if ($return && 0 === \strpos($return[\count($return) - 1], '@return')) {
if ($return && \strncmp($return[\count($return) - 1], '@return', \strlen('@return')) === 0) {
$return[] = '';
}
$deprecation = $definition->getDeprecation($id);
@ -956,13 +956,13 @@ EOTXT
}
$class = $this->dumpValue($callable[0]);
// If the class is a string we can optimize away
if (0 === \strpos($class, "'") && \false === \strpos($class, '$')) {
if (\strncmp($class, "'", \strlen("'")) === 0 && \strpos($class, '$') === \false) {
if ("''" === $class) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('Cannot dump definition: "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id ? 'The "' . $id . '"' : 'inline'));
}
return $return . \sprintf('%s::%s(%s)', $this->dumpLiteralClass($class), $callable[1], $arguments ? \implode(', ', $arguments) : '') . $tail;
}
if (0 === \strpos($class, 'new ')) {
if (\strncmp($class, 'new ', \strlen('new ')) === 0) {
return $return . \sprintf('(%s)->%s(%s)', $class, $callable[1], $arguments ? \implode(', ', $arguments) : '') . $tail;
}
return $return . \sprintf("[%s, '%s'](%s)", $class, $callable[1], $arguments ? \implode(', ', $arguments) : '') . $tail;
@ -1595,14 +1595,14 @@ EOF;
*/
private function dumpLiteralClass(string $class) : string
{
if (\false !== \strpos($class, '$')) {
if (\strpos($class, '$') !== \false) {
return \sprintf('${($_ = %s) && false ?: "_"}', $class);
}
if (0 !== \strpos($class, "'") || !\preg_match('/^\'(?:\\\\{2})?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\\\{2}[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*\'$/', $class)) {
if (\strncmp($class, "'", \strlen("'")) !== 0 || !\preg_match('/^\'(?:\\\\{2})?[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(?:\\\\{2}[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*\'$/', $class)) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\RuntimeException(\sprintf('Cannot dump definition because of invalid class name (%s).', $class ?: 'n/a'));
}
$class = \substr(\str_replace('\\\\', '\\', $class), 1, -1);
return 0 === \strpos($class, '\\') ? $class : '\\' . $class;
return \strncmp($class, '\\', \strlen('\\')) === 0 ? $class : '\\' . $class;
}
private function dumpParameter(string $name) : string
{
@ -1810,7 +1810,7 @@ EOF;
if ($shouldCacheValue && isset($this->exportedVariables[$value])) {
return $this->exportedVariables[$value];
}
if (\is_string($value) && \false !== \strpos($value, "\n")) {
if (\is_string($value) && \strpos($value, "\n") !== \false) {
$cleanParts = \explode("\n", $value);
$cleanParts = \array_map(function ($part) {
return \var_export($part, \true);
@ -1829,7 +1829,7 @@ EOF;
}
if ($resolveEnv && "'" === $export[0] && $export !== ($resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('string:%s').'"))) {
$export = $resolvedExport;
if (".''" === \substr($export, -3)) {
if (\substr_compare($export, ".''", -\strlen(".''")) === 0) {
$export = \substr($export, 0, -3);
if ("'" === $export[1]) {
$export = \substr_replace($export, '', 18, 7);
@ -1858,7 +1858,7 @@ EOF;
continue;
}
foreach (\get_declared_classes() as $class) {
if (0 === \strpos($class, 'ComposerAutoloaderInit') && $class::getLoader() === $autoloader[0]) {
if (\strncmp($class, 'ComposerAutoloaderInit', \strlen('ComposerAutoloaderInit')) === 0 && $class::getLoader() === $autoloader[0]) {
$file = \dirname((new \ReflectionClass($class))->getFileName(), 2) . '/autoload.php';
if (null !== $this->targetDirRegex && \preg_match($this->targetDirRegex . 'A', $file)) {
return $file;

View File

@ -293,7 +293,7 @@ class YamlDumper extends \RectorPrefix20210721\Symfony\Component\DependencyInjec
foreach ($parameters as $key => $value) {
if (\is_array($value)) {
$value = $this->prepareParameters($value, $escape);
} elseif ($value instanceof \RectorPrefix20210721\Symfony\Component\DependencyInjection\Reference || \is_string($value) && 0 === \strpos($value, '@')) {
} elseif ($value instanceof \RectorPrefix20210721\Symfony\Component\DependencyInjection\Reference || \is_string($value) && \strncmp($value, '@', \strlen('@')) === 0) {
$value = '@' . $value;
}
$filtered[$key] = $value;

View File

@ -96,7 +96,7 @@ class EnvVarProcessor implements \RectorPrefix20210721\Symfony\Component\Depende
$env = $getEnv($name);
} elseif (isset($_ENV[$name])) {
$env = $_ENV[$name];
} elseif (isset($_SERVER[$name]) && 0 !== \strpos($name, 'HTTP_')) {
} elseif (isset($_SERVER[$name]) && \strncmp($name, 'HTTP_', \strlen('HTTP_')) !== 0) {
$env = $_SERVER[$name];
} elseif (\false === ($env = \getenv($name)) || null === $env) {
// null is a possible value because of thread safety issues

View File

@ -62,7 +62,7 @@ abstract class Extension implements \RectorPrefix20210721\Symfony\Component\Depe
public function getAlias()
{
$className = static::class;
if ('Extension' != \substr($className, -9)) {
if (\substr_compare($className, 'Extension', -\strlen('Extension')) !== 0) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
}
$classBaseName = \substr(\strrchr($className, '\\'), 1, -9);
@ -76,7 +76,7 @@ abstract class Extension implements \RectorPrefix20210721\Symfony\Component\Depe
public function getConfiguration($config, $container)
{
$class = static::class;
if (\false !== \strpos($class, "\0")) {
if (\strpos($class, "\0") !== \false) {
return null;
// ignore anonymous classes
}

View File

@ -46,6 +46,6 @@ class DirectoryLoader extends \RectorPrefix20210721\Symfony\Component\Dependency
if ('directory' === $type) {
return \true;
}
return null === $type && \is_string($resource) && '/' === \substr($resource, -1);
return null === $type && \is_string($resource) && \substr_compare($resource, '/', -\strlen('/')) === 0;
}
}

View File

@ -82,7 +82,7 @@ abstract class FileLoader extends \RectorPrefix20210721\Symfony\Component\Config
*/
public function registerClasses($prototype, $namespace, $resource, $exclude = null)
{
if ('\\' !== \substr($namespace, -1)) {
if (\substr_compare($namespace, '\\', -\strlen('\\')) !== 0) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('Namespace prefix must end with a "\\": "%s".', $namespace));
}
if (!\preg_match('/^(?:[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*+\\\\)++$/', $namespace)) {
@ -172,7 +172,7 @@ abstract class FileLoader extends \RectorPrefix20210721\Symfony\Component\Config
foreach ($this->glob($pattern, \true, $resource, \false, \false, $excludePaths) as $path => $info) {
if (null === $prefixLen) {
$prefixLen = \strlen($resource->getPrefix());
if ($excludePrefix && 0 !== \strpos($excludePrefix, $resource->getPrefix())) {
if ($excludePrefix && \strncmp($excludePrefix, $resource->getPrefix(), \strlen($resource->getPrefix())) !== 0) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('Invalid "exclude" pattern when importing classes for "%s": make sure your "exclude" pattern (%s) is a subset of the "resource" pattern (%s).', $namespace, $excludePattern, $pattern));
}
}

View File

@ -282,7 +282,7 @@ class XmlFileLoader extends \RectorPrefix20210721\Symfony\Component\DependencyIn
if ('name' === $name && '' === $tagName) {
continue;
}
if (\false !== \strpos($name, '-') && \false === \strpos($name, '_') && !\array_key_exists($normalizedName = \str_replace('-', '_', $name), $parameters)) {
if (\strpos($name, '-') !== \false && \strpos($name, '_') === \false && !\array_key_exists($normalizedName = \str_replace('-', '_', $name), $parameters)) {
$parameters[$normalizedName] = \RectorPrefix20210721\Symfony\Component\Config\Util\XmlUtils::phpize($node->nodeValue);
}
// keep not normalized key
@ -533,7 +533,7 @@ class XmlFileLoader extends \RectorPrefix20210721\Symfony\Component\DependencyIn
\array_shift($parts);
$locationstart = 'phar:///';
}
} elseif ('\\' === \DIRECTORY_SEPARATOR && 0 === \strpos($location, '\\\\')) {
} elseif ('\\' === \DIRECTORY_SEPARATOR && \strncmp($location, '\\\\', \strlen('\\\\')) === 0) {
$locationstart = '';
}
$drive = '\\' === \DIRECTORY_SEPARATOR ? \array_shift($parts) . '/' : '';

View File

@ -154,7 +154,7 @@ class YamlFileLoader extends \RectorPrefix20210721\Symfony\Component\DependencyI
if (!$service || !\is_array($service)) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('Type definition "%s" must be a non-empty array within "_instanceof" in "%s". Check your YAML syntax.', $id, $file));
}
if (\is_string($service) && 0 === \strpos($service, '@')) {
if (\is_string($service) && \strncmp($service, '@', \strlen('@')) === 0) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('Type definition "%s" cannot be an alias within "_instanceof" in "%s". Check your YAML syntax.', $id, $file));
}
$this->parseDefinition($id, $service, $file, []);
@ -225,7 +225,7 @@ class YamlFileLoader extends \RectorPrefix20210721\Symfony\Component\DependencyI
private function isUsingShortSyntax(array $service) : bool
{
foreach ($service as $key => $value) {
if (\is_string($key) && ('' === $key || '$' !== $key[0] && \false === \strpos($key, '\\'))) {
if (\is_string($key) && ('' === $key || '$' !== $key[0] && \strpos($key, '\\') === \false)) {
return \false;
}
}
@ -243,7 +243,7 @@ class YamlFileLoader extends \RectorPrefix20210721\Symfony\Component\DependencyI
if (\preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id));
}
if (\is_string($service) && 0 === \strpos($service, '@')) {
if (\is_string($service) && \strncmp($service, '@', \strlen('@')) === 0) {
$alias = new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Alias(\substr($service, 1));
if (isset($defaults['public'])) {
$alias->setPublic($defaults['public']);
@ -528,7 +528,7 @@ class YamlFileLoader extends \RectorPrefix20210721\Symfony\Component\DependencyI
{
if (\is_string($callable)) {
if ('' !== $callable && '@' === $callable[0]) {
if (\false === \strpos($callable, ':')) {
if (\strpos($callable, ':') === \false) {
return [$this->resolveServices($callable, $file), '__invoke'];
}
throw new \RectorPrefix20210721\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException(\sprintf('The value of the "%s" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" with "%s" in "%s").', $parameter, $id, $callable, \substr($callable, 1), $file));
@ -683,19 +683,19 @@ class YamlFileLoader extends \RectorPrefix20210721\Symfony\Component\DependencyI
foreach ($value as $k => $v) {
$value[$k] = $this->resolveServices($v, $file, $isParameter);
}
} elseif (\is_string($value) && 0 === \strpos($value, '@=')) {
} elseif (\is_string($value) && \strncmp($value, '@=', \strlen('@=')) === 0) {
if (!\class_exists(\RectorPrefix20210721\Symfony\Component\ExpressionLanguage\Expression::class)) {
throw new \LogicException('The "@=" expression syntax cannot be used without the ExpressionLanguage component. Try running "composer require symfony/expression-language".');
}
return new \RectorPrefix20210721\Symfony\Component\ExpressionLanguage\Expression(\substr($value, 2));
} elseif (\is_string($value) && 0 === \strpos($value, '@')) {
if (0 === \strpos($value, '@@')) {
} elseif (\is_string($value) && \strncmp($value, '@', \strlen('@')) === 0) {
if (\strncmp($value, '@@', \strlen('@@')) === 0) {
$value = \substr($value, 1);
$invalidBehavior = null;
} elseif (0 === \strpos($value, '@!')) {
} elseif (\strncmp($value, '@!', \strlen('@!')) === 0) {
$value = \substr($value, 2);
$invalidBehavior = \RectorPrefix20210721\Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE;
} elseif (0 === \strpos($value, '@?')) {
} elseif (\strncmp($value, '@?', \strlen('@?')) === 0) {
$value = \substr($value, 2);
$invalidBehavior = \RectorPrefix20210721\Symfony\Component\DependencyInjection\ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
} else {

View File

@ -28,7 +28,7 @@ class EnvPlaceholderParameterBag extends \RectorPrefix20210721\Symfony\Component
*/
public function get($name)
{
if (0 === \strpos($name, 'env(') && ')' === \substr($name, -1) && 'env()' !== $name) {
if (\strncmp($name, 'env(', \strlen('env(')) === 0 && \substr_compare($name, ')', -\strlen(')')) === 0 && 'env()' !== $name) {
$env = \substr($name, 4, -1);
if (isset($this->envPlaceholders[$env])) {
foreach ($this->envPlaceholders[$env] as $placeholder) {

View File

@ -63,12 +63,12 @@ class ParameterBag implements \RectorPrefix20210721\Symfony\Component\Dependency
$alternatives = [];
foreach ($this->parameters as $key => $parameterValue) {
$lev = \levenshtein($name, $key);
if ($lev <= \strlen($name) / 3 || \false !== \strpos($key, $name)) {
if ($lev <= \strlen($name) / 3 || \strpos($key, $name) !== \false) {
$alternatives[] = $key;
}
}
$nonNestedAlternative = null;
if (!\count($alternatives) && \false !== \strpos($name, '.')) {
if (!\count($alternatives) && \strpos($name, '.') !== \false) {
$namePartsLength = \array_map('strlen', \explode('.', $name));
$key = \substr($name, 0, -1 * (1 + \array_pop($namePartsLength)));
while (\count($namePartsLength)) {

View File

@ -19,7 +19,7 @@
"php": ">=7.2.5",
"psr\/container": "^1.1.1",
"symfony\/deprecation-contracts": "^2.1",
"symfony\/polyfill-php80": "^1.15",
"symfony\/polyfill-php80": "^1.16",
"symfony\/service-contracts": "^1.1.6|^2"
},
"require-dev": {