Updated Rector to commit 7f9c6b0f0a2f6093c3da6b7d1326c4add4e7040f

7f9c6b0f0a [TypeDeclaration] Convert inline @var tag to assert() (#6300)
This commit is contained in:
Tomas Votruba 2024-09-13 07:50:10 +00:00
parent 61420a6bd4
commit eb623ce3a0
14 changed files with 355 additions and 29 deletions

View File

@ -0,0 +1,148 @@
<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\PhpDocParser;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\CallableType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareIntersectionTypeNode;
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
use Rector\StaticTypeMapper\Mapper\ScalarStringToTypeMapper;
final class TypeExpressionFromVarTagResolver
{
/**
* @readonly
* @var \Rector\StaticTypeMapper\Mapper\ScalarStringToTypeMapper
*/
private $scalarStringToTypeMapper;
public function __construct(ScalarStringToTypeMapper $scalarStringToTypeMapper)
{
$this->scalarStringToTypeMapper = $scalarStringToTypeMapper;
}
public function resolveTypeExpressionFromVarTag(TypeNode $typeNode, Variable $variable) : ?Expr
{
if ($typeNode instanceof IdentifierTypeNode) {
$scalarType = $this->scalarStringToTypeMapper->mapScalarStringToType($typeNode->name);
$scalarTypeFunction = $this->getScalarTypeFunction(\get_class($scalarType));
if ($scalarTypeFunction !== null) {
$arg = new Arg($variable);
return new FuncCall(new Name($scalarTypeFunction), [$arg]);
}
if ($scalarType instanceof NullType) {
return new Identical($variable, new ConstFetch(new Name('null')));
}
if ($scalarType instanceof ConstantBooleanType) {
return new Identical($variable, new ConstFetch(new Name($scalarType->getValue() ? 'true' : 'false')));
}
if ($scalarType instanceof MixedType && !$scalarType->isExplicitMixed()) {
return new Instanceof_($variable, new Name($typeNode->name));
}
} elseif ($typeNode instanceof NullableTypeNode) {
$unionExpressions = [];
$nullableTypeExpression = $this->resolveTypeExpressionFromVarTag($typeNode->type, $variable);
if (!$nullableTypeExpression instanceof Expr) {
return null;
}
$unionExpressions[] = $nullableTypeExpression;
$nullExpression = $this->resolveTypeExpressionFromVarTag(new IdentifierTypeNode('null'), $variable);
\assert($nullExpression instanceof Expr);
$unionExpressions[] = $nullExpression;
return $this->generateOrExpression($unionExpressions);
} elseif ($typeNode instanceof BracketsAwareUnionTypeNode) {
$unionExpressions = [];
foreach ($typeNode->types as $typeNode) {
$unionExpression = $this->resolveTypeExpressionFromVarTag($typeNode, $variable);
if (!$unionExpression instanceof Expr) {
return null;
}
$unionExpressions[] = $unionExpression;
}
return $this->generateOrExpression($unionExpressions);
} elseif ($typeNode instanceof BracketsAwareIntersectionTypeNode) {
$intersectionExpressions = [];
foreach ($typeNode->types as $typeNode) {
$intersectionExpression = $this->resolveTypeExpressionFromVarTag($typeNode, $variable);
if (!$intersectionExpression instanceof Expr) {
return null;
}
$intersectionExpressions[] = $intersectionExpression;
}
return $this->generateAndExpression($intersectionExpressions);
}
return null;
}
/**
* @param Expr[] $unionExpressions
* @return BooleanOr
*/
private function generateOrExpression(array $unionExpressions)
{
$booleanOr = new BooleanOr($unionExpressions[0], $unionExpressions[1]);
if (\count($unionExpressions) == 2) {
return $booleanOr;
}
\array_splice($unionExpressions, 0, 2, [$booleanOr]);
return $this->generateOrExpression($unionExpressions);
}
/**
* @param Expr[] $intersectionExpressions
* @return BooleanAnd
*/
private function generateAndExpression(array $intersectionExpressions)
{
$booleanAnd = new BooleanAnd($intersectionExpressions[0], $intersectionExpressions[1]);
if (\count($intersectionExpressions) == 2) {
return $booleanAnd;
}
\array_splice($intersectionExpressions, 0, 2, [$booleanAnd]);
return $this->generateAndExpression($intersectionExpressions);
}
/**
* @param class-string $className
*/
private function getScalarTypeFunction(string $className) : ?string
{
switch ($className) {
case IntegerType::class:
return 'is_int';
case BooleanType::class:
return 'is_bool';
case FloatType::class:
return 'is_float';
case StringType::class:
return 'is_string';
case ArrayType::class:
return 'is_array';
case CallableType::class:
return 'is_callable';
case ObjectWithoutClassType::class:
return 'is_object';
case IterableType::class:
return 'is_iterable';
default:
return null;
}
}
}

View File

@ -0,0 +1,112 @@
<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\Rector\Expression;
use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Expression;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Rector\AbstractRector;
use Rector\TypeDeclaration\PhpDocParser\TypeExpressionFromVarTagResolver;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\TypeDeclaration\Rector\Expression\InlineVarDocTagToAssertRector\InlineVarDocTagToAssertRectorTest
*/
final class InlineVarDocTagToAssertRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/
private $phpDocInfoFactory;
/**
* @readonly
* @var \Rector\Comments\NodeDocBlock\DocBlockUpdater
*/
private $docBlockUpdater;
/**
* @readonly
* @var \Rector\TypeDeclaration\PhpDocParser\TypeExpressionFromVarTagResolver
*/
private $typeExpressionFromVarTagResolver;
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, DocBlockUpdater $docBlockUpdater, TypeExpressionFromVarTagResolver $typeExpressionFromVarTagResolver)
{
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->docBlockUpdater = $docBlockUpdater;
$this->typeExpressionFromVarTagResolver = $typeExpressionFromVarTagResolver;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Convert inline @var tags to calls to assert()', [new CodeSample(<<<'CODE_SAMPLE'
/** @var Foo $foo */
$foo = createFoo();
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$foo = createFoo();
assert($foo instanceof Foo);
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Expression::class];
}
/**
* @param Expression $node
* @return Node[]|null
*/
public function refactor(Node $node) : ?array
{
if (!$node->expr instanceof Assign) {
return null;
}
if (!$node->expr->var instanceof Variable) {
return null;
}
$docComment = $node->getDocComment();
if (!$docComment instanceof Doc) {
return null;
}
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
if (!$phpDocInfo instanceof PhpDocInfo || $phpDocInfo->getPhpDocNode()->children === []) {
return null;
}
$expressionVariableName = $node->expr->var->name;
foreach ($phpDocInfo->getPhpDocNode()->getVarTagValues() as $varTagValueNode) {
//remove $ from variable name
$variableName = \substr($varTagValueNode->variableName, 1);
if ($variableName === $expressionVariableName && $varTagValueNode->description === '') {
$typeExpression = $this->typeExpressionFromVarTagResolver->resolveTypeExpressionFromVarTag($varTagValueNode->type, new Variable($variableName));
if ($typeExpression instanceof Expr) {
$phpDocInfo->removeByType(VarTagValueNode::class, $variableName);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
$arg = new Arg($typeExpression);
$funcCall = new FuncCall(new Name('assert'), [$arg]);
$expression = new Expression($funcCall);
return [$node, $expression];
}
}
}
return null;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::STRING_IN_ASSERT_ARG;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '71fb2e4c9346bf6ce6b057ff3d77511662f7913c';
public const PACKAGE_VERSION = '7f9c6b0f0a2f6093c3da6b7d1326c4add4e7040f';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-09-09 21:16:22';
public const RELEASE_DATE = '2024-09-13 14:47:41';
/**
* @var int
*/

View File

@ -20,6 +20,7 @@ use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\Application\ChangedNodeScopeRefresher;
use Rector\Application\Provider\CurrentFileProvider;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Contract\Rector\RectorInterface;
use Rector\Exception\ShouldNotHappenException;
@ -240,7 +241,17 @@ CODE_SAMPLE;
if ($oldNode instanceof InlineHTML) {
return;
}
$newNode->setAttribute(AttributeKey::PHP_DOC_INFO, $oldNode->getAttribute(AttributeKey::PHP_DOC_INFO));
$oldPhpDocInfo = $oldNode->getAttribute(AttributeKey::PHP_DOC_INFO);
$newPhpDocInfo = $newNode->getAttribute(AttributeKey::PHP_DOC_INFO);
if ($newPhpDocInfo instanceof PhpDocInfo) {
if (!$oldPhpDocInfo instanceof PhpDocInfo) {
return;
}
if ((string) $oldPhpDocInfo->getPhpDocNode() !== (string) $newPhpDocInfo->getPhpDocNode()) {
return;
}
}
$newNode->setAttribute(AttributeKey::PHP_DOC_INFO, $oldPhpDocInfo);
if (!$newNode instanceof Nop) {
$newNode->setAttribute(AttributeKey::COMMENTS, $oldNode->getAttribute(AttributeKey::COMMENTS));
}

View File

@ -460,6 +460,7 @@ return array(
'RectorPrefix202409\\Illuminate\\Container\\Attributes\\Database' => $vendorDir . '/illuminate/container/Attributes/Database.php',
'RectorPrefix202409\\Illuminate\\Container\\Attributes\\Log' => $vendorDir . '/illuminate/container/Attributes/Log.php',
'RectorPrefix202409\\Illuminate\\Container\\Attributes\\Storage' => $vendorDir . '/illuminate/container/Attributes/Storage.php',
'RectorPrefix202409\\Illuminate\\Container\\Attributes\\Tag' => $vendorDir . '/illuminate/container/Attributes/Tag.php',
'RectorPrefix202409\\Illuminate\\Container\\BoundMethod' => $vendorDir . '/illuminate/container/BoundMethod.php',
'RectorPrefix202409\\Illuminate\\Container\\Container' => $vendorDir . '/illuminate/container/Container.php',
'RectorPrefix202409\\Illuminate\\Container\\ContextualBindingBuilder' => $vendorDir . '/illuminate/container/ContextualBindingBuilder.php',
@ -493,6 +494,7 @@ return array(
'RectorPrefix202409\\Illuminate\\Contracts\\Cache\\LockTimeoutException' => $vendorDir . '/illuminate/contracts/Cache/LockTimeoutException.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Cache\\Repository' => $vendorDir . '/illuminate/contracts/Cache/Repository.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Cache\\Store' => $vendorDir . '/illuminate/contracts/Cache/Store.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Concurrency\\Driver' => $vendorDir . '/illuminate/contracts/Concurrency/Driver.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Config\\Repository' => $vendorDir . '/illuminate/contracts/Config/Repository.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Console\\Application' => $vendorDir . '/illuminate/contracts/Console/Application.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Console\\Isolatable' => $vendorDir . '/illuminate/contracts/Console/Isolatable.php',
@ -2431,6 +2433,7 @@ return array(
'Rector\\TypeDeclaration\\NodeTypeAnalyzer\\PropertyTypeDecorator' => $baseDir . '/rules/TypeDeclaration/NodeTypeAnalyzer/PropertyTypeDecorator.php',
'Rector\\TypeDeclaration\\PHPStan\\ObjectTypeSpecifier' => $baseDir . '/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php',
'Rector\\TypeDeclaration\\PhpDocParser\\ParamPhpDocNodeFactory' => $baseDir . '/rules/TypeDeclaration/PhpDocParser/ParamPhpDocNodeFactory.php',
'Rector\\TypeDeclaration\\PhpDocParser\\TypeExpressionFromVarTagResolver' => $baseDir . '/rules/TypeDeclaration/PhpDocParser/TypeExpressionFromVarTagResolver.php',
'Rector\\TypeDeclaration\\Rector\\ArrowFunction\\AddArrowFunctionReturnTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\BooleanAnd\\BinaryOpNullableToInstanceofRector' => $baseDir . '/rules/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector.php',
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddMethodCallBasedStrictParamTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php',
@ -2479,6 +2482,7 @@ return array(
'Rector\\TypeDeclaration\\Rector\\Closure\\AddClosureVoidReturnTypeWhereNoReturnRector' => $baseDir . '/rules/TypeDeclaration/Rector/Closure/AddClosureVoidReturnTypeWhereNoReturnRector.php',
'Rector\\TypeDeclaration\\Rector\\Closure\\ClosureReturnTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/Closure/ClosureReturnTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\Empty_\\EmptyOnNullableObjectToInstanceOfRector' => $baseDir . '/rules/TypeDeclaration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector.php',
'Rector\\TypeDeclaration\\Rector\\Expression\\InlineVarDocTagToAssertRector' => $baseDir . '/rules/TypeDeclaration/Rector/Expression/InlineVarDocTagToAssertRector.php',
'Rector\\TypeDeclaration\\Rector\\FunctionLike\\AddClosureParamTypeFromArgRector' => $baseDir . '/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeFromArgRector.php',
'Rector\\TypeDeclaration\\Rector\\FunctionLike\\AddClosureParamTypeFromObjectRector' => $baseDir . '/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeFromObjectRector.php',
'Rector\\TypeDeclaration\\Rector\\FunctionLike\\AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector' => $baseDir . '/rules/TypeDeclaration/Rector/FunctionLike/AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector.php',

View File

@ -679,6 +679,7 @@ class ComposerStaticInit8271306f0ebaff89706816bb96249bfb
'RectorPrefix202409\\Illuminate\\Container\\Attributes\\Database' => __DIR__ . '/..' . '/illuminate/container/Attributes/Database.php',
'RectorPrefix202409\\Illuminate\\Container\\Attributes\\Log' => __DIR__ . '/..' . '/illuminate/container/Attributes/Log.php',
'RectorPrefix202409\\Illuminate\\Container\\Attributes\\Storage' => __DIR__ . '/..' . '/illuminate/container/Attributes/Storage.php',
'RectorPrefix202409\\Illuminate\\Container\\Attributes\\Tag' => __DIR__ . '/..' . '/illuminate/container/Attributes/Tag.php',
'RectorPrefix202409\\Illuminate\\Container\\BoundMethod' => __DIR__ . '/..' . '/illuminate/container/BoundMethod.php',
'RectorPrefix202409\\Illuminate\\Container\\Container' => __DIR__ . '/..' . '/illuminate/container/Container.php',
'RectorPrefix202409\\Illuminate\\Container\\ContextualBindingBuilder' => __DIR__ . '/..' . '/illuminate/container/ContextualBindingBuilder.php',
@ -712,6 +713,7 @@ class ComposerStaticInit8271306f0ebaff89706816bb96249bfb
'RectorPrefix202409\\Illuminate\\Contracts\\Cache\\LockTimeoutException' => __DIR__ . '/..' . '/illuminate/contracts/Cache/LockTimeoutException.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Cache\\Repository' => __DIR__ . '/..' . '/illuminate/contracts/Cache/Repository.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Cache\\Store' => __DIR__ . '/..' . '/illuminate/contracts/Cache/Store.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Concurrency\\Driver' => __DIR__ . '/..' . '/illuminate/contracts/Concurrency/Driver.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Config\\Repository' => __DIR__ . '/..' . '/illuminate/contracts/Config/Repository.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Console\\Application' => __DIR__ . '/..' . '/illuminate/contracts/Console/Application.php',
'RectorPrefix202409\\Illuminate\\Contracts\\Console\\Isolatable' => __DIR__ . '/..' . '/illuminate/contracts/Console/Isolatable.php',
@ -2650,6 +2652,7 @@ class ComposerStaticInit8271306f0ebaff89706816bb96249bfb
'Rector\\TypeDeclaration\\NodeTypeAnalyzer\\PropertyTypeDecorator' => __DIR__ . '/../..' . '/rules/TypeDeclaration/NodeTypeAnalyzer/PropertyTypeDecorator.php',
'Rector\\TypeDeclaration\\PHPStan\\ObjectTypeSpecifier' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php',
'Rector\\TypeDeclaration\\PhpDocParser\\ParamPhpDocNodeFactory' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PhpDocParser/ParamPhpDocNodeFactory.php',
'Rector\\TypeDeclaration\\PhpDocParser\\TypeExpressionFromVarTagResolver' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PhpDocParser/TypeExpressionFromVarTagResolver.php',
'Rector\\TypeDeclaration\\Rector\\ArrowFunction\\AddArrowFunctionReturnTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\BooleanAnd\\BinaryOpNullableToInstanceofRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector.php',
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddMethodCallBasedStrictParamTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php',
@ -2698,6 +2701,7 @@ class ComposerStaticInit8271306f0ebaff89706816bb96249bfb
'Rector\\TypeDeclaration\\Rector\\Closure\\AddClosureVoidReturnTypeWhereNoReturnRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Closure/AddClosureVoidReturnTypeWhereNoReturnRector.php',
'Rector\\TypeDeclaration\\Rector\\Closure\\ClosureReturnTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Closure/ClosureReturnTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\Empty_\\EmptyOnNullableObjectToInstanceOfRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector.php',
'Rector\\TypeDeclaration\\Rector\\Expression\\InlineVarDocTagToAssertRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/Expression/InlineVarDocTagToAssertRector.php',
'Rector\\TypeDeclaration\\Rector\\FunctionLike\\AddClosureParamTypeFromArgRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeFromArgRector.php',
'Rector\\TypeDeclaration\\Rector\\FunctionLike\\AddClosureParamTypeFromObjectRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeFromObjectRector.php',
'Rector\\TypeDeclaration\\Rector\\FunctionLike\\AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/FunctionLike/AddParamTypeForFunctionLikeWithinCallLikeArgDeclarationRector.php',

View File

@ -512,17 +512,17 @@
},
{
"name": "illuminate\/container",
"version": "v11.22.0",
"version_normalized": "11.22.0.0",
"version": "v11.23.4",
"version_normalized": "11.23.4.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/container.git",
"reference": "85e3396fde3139eae3f37128222c9a7746ca4bbb"
"reference": "66d20471c8c55ef056044dc1ff16da90d7b4d649"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/illuminate\/container\/zipball\/85e3396fde3139eae3f37128222c9a7746ca4bbb",
"reference": "85e3396fde3139eae3f37128222c9a7746ca4bbb",
"url": "https:\/\/api.github.com\/repos\/illuminate\/container\/zipball\/66d20471c8c55ef056044dc1ff16da90d7b4d649",
"reference": "66d20471c8c55ef056044dc1ff16da90d7b4d649",
"shasum": ""
},
"require": {
@ -533,7 +533,7 @@
"provide": {
"psr\/container-implementation": "1.1|2.0"
},
"time": "2024-08-21T16:01:30+00:00",
"time": "2024-09-11T20:15:17+00:00",
"type": "library",
"extra": {
"branch-alias": {
@ -569,17 +569,17 @@
},
{
"name": "illuminate\/contracts",
"version": "v11.22.0",
"version_normalized": "11.22.0.0",
"version": "v11.23.4",
"version_normalized": "11.23.4.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/contracts.git",
"reference": "af9b459f195d57f279ec30a45446ddaeb3337bcb"
"reference": "272aad6ca259425d50b266218be5a7955a4c8af3"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/illuminate\/contracts\/zipball\/af9b459f195d57f279ec30a45446ddaeb3337bcb",
"reference": "af9b459f195d57f279ec30a45446ddaeb3337bcb",
"url": "https:\/\/api.github.com\/repos\/illuminate\/contracts\/zipball\/272aad6ca259425d50b266218be5a7955a4c8af3",
"reference": "272aad6ca259425d50b266218be5a7955a4c8af3",
"shasum": ""
},
"require": {
@ -587,7 +587,7 @@
"psr\/container": "^1.1.1|^2.0.1",
"psr\/simple-cache": "^1.0|^2.0|^3.0"
},
"time": "2024-08-21T16:02:16+00:00",
"time": "2024-09-11T20:06:38+00:00",
"type": "library",
"extra": {
"branch-alias": {
@ -973,23 +973,23 @@
},
{
"name": "psr\/log",
"version": "3.0.1",
"version_normalized": "3.0.1.0",
"version": "3.0.2",
"version_normalized": "3.0.2.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/php-fig\/log.git",
"reference": "79dff0b268932c640297f5208d6298f71855c03e"
"reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/php-fig\/log\/zipball\/79dff0b268932c640297f5208d6298f71855c03e",
"reference": "79dff0b268932c640297f5208d6298f71855c03e",
"url": "https:\/\/api.github.com\/repos\/php-fig\/log\/zipball\/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3",
"reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"time": "2024-08-21T13:31:24+00:00",
"time": "2024-09-11T13:17:53+00:00",
"type": "library",
"extra": {
"branch-alias": {
@ -1020,7 +1020,7 @@
"psr-3"
],
"support": {
"source": "https:\/\/github.com\/php-fig\/log\/tree\/3.0.1"
"source": "https:\/\/github.com\/php-fig\/log\/tree\/3.0.2"
},
"install-path": "..\/psr\/log"
},

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,31 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202409\Illuminate\Container\Attributes;
use Attribute;
use RectorPrefix202409\Illuminate\Contracts\Container\Container;
use RectorPrefix202409\Illuminate\Contracts\Container\ContextualAttribute;
#[Attribute(Attribute::TARGET_PARAMETER)]
final class Tag implements ContextualAttribute
{
/**
* @var string
*/
public $tag;
public function __construct(string $tag)
{
$this->tag = $tag;
}
/**
* Resolve the tag.
*
* @param self $attribute
* @param \Illuminate\Contracts\Container\Container $container
* @return mixed
*/
public static function resolve(self $attribute, Container $container)
{
return $container->tagged($attribute->tag);
}
}

View File

@ -1292,10 +1292,7 @@ class Container implements ArrayAccess, ContainerContract
*/
public static function getInstance()
{
if (\is_null(static::$instance)) {
static::$instance = new static();
}
return static::$instance;
return static::$instance = static::$instance ?? new static();
}
/**
* Set the shared instance of the container.

View File

@ -0,0 +1,18 @@
<?php
namespace RectorPrefix202409\Illuminate\Contracts\Concurrency;
use Closure;
interface Driver
{
/**
* Run the given tasks concurrently and return an array containing the results.
* @param \Closure|mixed[] $tasks
*/
public function run($tasks) : array;
/**
* Start the given tasks in the background.
* @param \Closure|mixed[] $tasks
*/
public function background($tasks) : void;
}

View File

@ -13,7 +13,7 @@ interface InvokableRule
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @param \Closure(string, ?string = null): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function __invoke(string $attribute, $value, Closure $fail);

View File

@ -10,7 +10,7 @@ interface ValidationRule
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @param \Closure(string, ?string = null): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function validate(string $attribute, $value, Closure $fail) : void;

View File

@ -89,6 +89,7 @@ interface LoggerInterface
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param mixed[] $context
*
* @throws \Psr\Log\InvalidArgumentException