2222use PHPStan \Analyser \ConditionalExpressionHolder ;
2323use PHPStan \Analyser \ExpressionContext ;
2424use PHPStan \Analyser \ExpressionTypeHolder ;
25+ use PHPStan \Analyser \Generator \AssignHelper ;
2526use PHPStan \Analyser \Generator \ExprAnalysisRequest ;
2627use PHPStan \Analyser \Generator \ExprAnalysisResult ;
2728use PHPStan \Analyser \Generator \ExprHandler ;
29+ use PHPStan \Analyser \Generator \GeneratorNodeScopeResolver ;
2830use PHPStan \Analyser \Generator \GeneratorScope ;
2931use PHPStan \Analyser \Generator \InternalThrowPoint ;
3032use PHPStan \Analyser \Generator \NodeCallbackRequest ;
3133use PHPStan \Analyser \Generator \NoopNodeCallback ;
3234use PHPStan \Analyser \Generator \TypeExprRequest ;
33- use PHPStan \Analyser \Generator \TypeExprResult ;
3435use PHPStan \Analyser \ImpurePoint ;
3536use PHPStan \Analyser \Scope ;
3637use PHPStan \Analyser \SpecifiedTypes ;
7879
7980/**
8081 * @implements ExprHandler<Assign|Expr\AssignRef>
82+ * @phpstan-import-type GeneratorTValueType from GeneratorNodeScopeResolver
83+ * @phpstan-import-type GeneratorTSendType from GeneratorNodeScopeResolver
8184 */
8285#[AutowiredService]
8386final class AssignHandler implements ExprHandler
@@ -86,6 +89,7 @@ final class AssignHandler implements ExprHandler
8689 public function __construct (
8790 private PhpVersion $ phpVersion ,
8891 private FileTypeMapper $ fileTypeMapper ,
92+ private AssignHelper $ assignHelper ,
8993 #[AutowiredParameter(ref: '%exceptions.implicitThrows% ' )]
9094 private readonly bool $ implicitThrows ,
9195 )
@@ -226,7 +230,7 @@ private function getAssignedVariables(Expr $expr): array
226230
227231 /**
228232 * @param array<int, string> $variableNames
229- * @return Generator<int, ExprAnalysisRequest|TypeExprRequest, ExprAnalysisResult|TypeExprResult , GeneratorScope>
233+ * @return Generator<int, GeneratorTValueType, GeneratorTSendType , GeneratorScope>
230234 */
231235 private function processVarAnnotation (GeneratorScope $ scope , array $ variableNames , Node \Stmt $ node , bool &$ changed = false ): Generator
232236 {
@@ -278,7 +282,7 @@ private function processVarAnnotation(GeneratorScope $scope, array $variableName
278282
279283 /**
280284 * @param (callable(Node, Scope, callable(Node, Scope): void): void)|null $alternativeNodeCallback
281- * @return Generator<int, ExprAnalysisRequest|NodeCallbackRequest|TypeExprRequest, ExprAnalysisResult|TypeExprResult , GeneratorScope>
285+ * @return Generator<int, GeneratorTValueType, GeneratorTSendType , GeneratorScope>
282286 */
283287 private function processStmtVarAnnotation (GeneratorScope $ scope , Node \Stmt $ stmt , ?Expr $ defaultExpr , ?callable $ alternativeNodeCallback ): Generator
284288 {
@@ -366,10 +370,10 @@ private function processStmtVarAnnotation(GeneratorScope $scope, Node\Stmt $stmt
366370
367371 /**
368372 * @param (callable(Node, Scope, callable(Node, Scope): void): void)|null $alternativeNodeCallback
369- * @param Closure(GeneratorScope $scope): Generator<int, ExprAnalysisRequest|NodeCallbackRequest|TypeExprRequest, ExprAnalysisResult|TypeExprResult , ExprAnalysisResult> $processExprCallback
370- * @return Generator<int, ExprAnalysisRequest|NodeCallbackRequest|TypeExprRequest, ExprAnalysisResult|TypeExprResult , ExprAnalysisResult>
373+ * @param Closure(GeneratorScope $scope): Generator<int, GeneratorTValueType, GeneratorTSendType , ExprAnalysisResult> $processExprCallback
374+ * @return Generator<int, GeneratorTValueType, GeneratorTSendType , ExprAnalysisResult>
371375 */
372- private function processAssignVar (
376+ public function processAssignVar (
373377 GeneratorScope $ scope ,
374378 Node \Stmt $ stmt ,
375379 Expr $ var ,
@@ -911,7 +915,7 @@ private function processAssignVar(
911915 if ($ enterExpressionAssign ) {
912916 $ itemScope = $ itemScope ->enterExpressionAssign ($ arrayItem ->value );
913917 }
914- $ itemScope = $ this ->lookForSetAllowedUndefinedExpressions ($ itemScope , $ arrayItem ->value );
918+ $ itemScope = $ this ->assignHelper -> lookForSetAllowedUndefinedExpressions ($ itemScope , $ arrayItem ->value );
915919 yield new NodeCallbackRequest ($ arrayItem , $ itemScope , $ alternativeNodeCallback );
916920 if ($ arrayItem ->key !== null ) {
917921 $ keyResult = yield new ExprAnalysisRequest ($ stmt , $ arrayItem ->key , $ itemScope , $ context ->enterDeep (), $ alternativeNodeCallback );
@@ -1101,7 +1105,7 @@ static function (GeneratorScope $scope): Generator {
11011105
11021106 /**
11031107 * @param array<string, ConditionalExpressionHolder[]> $conditionalExpressions
1104- * @return Generator<int, ExprAnalysisRequest|TypeExprRequest, ExprAnalysisResult|TypeExprResult , array<string, ConditionalExpressionHolder[]>>
1108+ * @return Generator<int, GeneratorTValueType, GeneratorTSendType , array<string, ConditionalExpressionHolder[]>>
11051109 */
11061110 private function processSureTypesForConditionalExpressionsAfterAssign (string $ variableName , array $ conditionalExpressions , SpecifiedTypes $ specifiedTypes , Type $ variableType ): Generator
11071111 {
@@ -1135,7 +1139,7 @@ private function processSureTypesForConditionalExpressionsAfterAssign(string $va
11351139
11361140 /**
11371141 * @param array<string, ConditionalExpressionHolder[]> $conditionalExpressions
1138- * @return Generator<int, ExprAnalysisRequest|TypeExprRequest, ExprAnalysisResult|TypeExprResult , array<string, ConditionalExpressionHolder[]>>
1142+ * @return Generator<int, GeneratorTValueType, GeneratorTSendType , array<string, ConditionalExpressionHolder[]>>
11391143 */
11401144 private function processSureNotTypesForConditionalExpressionsAfterAssign (string $ variableName , array $ conditionalExpressions , SpecifiedTypes $ specifiedTypes , Type $ variableType ): Generator
11411145 {
@@ -1167,39 +1171,6 @@ private function processSureNotTypesForConditionalExpressionsAfterAssign(string
11671171 return $ conditionalExpressions ;
11681172 }
11691173
1170- private function lookForSetAllowedUndefinedExpressions (GeneratorScope $ scope , Expr $ expr ): GeneratorScope
1171- {
1172- return $ this ->lookForExpressionCallback ($ scope , $ expr , static fn (GeneratorScope $ scope , Expr $ expr ): GeneratorScope => $ scope ->setAllowedUndefinedExpression ($ expr ));
1173- }
1174-
1175- /**
1176- * @param Closure(GeneratorScope $scope, Expr $expr): GeneratorScope $callback
1177- */
1178- private function lookForExpressionCallback (GeneratorScope $ scope , Expr $ expr , Closure $ callback ): GeneratorScope
1179- {
1180- if (!$ expr instanceof ArrayDimFetch || $ expr ->dim !== null ) {
1181- $ scope = $ callback ($ scope , $ expr );
1182- }
1183-
1184- if ($ expr instanceof ArrayDimFetch) {
1185- $ scope = $ this ->lookForExpressionCallback ($ scope , $ expr ->var , $ callback );
1186- } elseif ($ expr instanceof PropertyFetch || $ expr instanceof Expr \NullsafePropertyFetch) {
1187- $ scope = $ this ->lookForExpressionCallback ($ scope , $ expr ->var , $ callback );
1188- } elseif ($ expr instanceof StaticPropertyFetch && $ expr ->class instanceof Expr) {
1189- $ scope = $ this ->lookForExpressionCallback ($ scope , $ expr ->class , $ callback );
1190- } elseif ($ expr instanceof List_) {
1191- foreach ($ expr ->items as $ item ) {
1192- if ($ item === null ) {
1193- continue ;
1194- }
1195-
1196- $ scope = $ this ->lookForExpressionCallback ($ scope , $ item ->value , $ callback );
1197- }
1198- }
1199-
1200- return $ scope ;
1201- }
1202-
12031174 private function unwrapAssign (Expr $ expr ): Expr
12041175 {
12051176 if ($ expr instanceof Assign) {
@@ -1234,7 +1205,7 @@ private function isImplicitArrayCreation(array $dimFetchStack, GeneratorScope $s
12341205 * @param list<ArrayDimFetch> $dimFetchStack
12351206 * @param list<array{Type|null, ArrayDimFetch}> $offsetTypes
12361207 *
1237- * @return Generator<int, ExprAnalysisRequest|TypeExprRequest, ExprAnalysisResult|TypeExprResult , array{Type, list<array{Expr, Type}>}>
1208+ * @return Generator<int, GeneratorTValueType, GeneratorTSendType , array{Type, list<array{Expr, Type}>}>
12381209 */
12391210 private function produceArrayDimFetchAssignValueToWrite (array $ dimFetchStack , array $ offsetTypes , Type $ offsetValueType , Type $ valueToWrite , GeneratorScope $ scope , bool $ native ): Generator
12401211 {
0 commit comments