@@ -120,6 +120,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
120120 if ($ isUpdate ) {
121121 require_once __DIR__ . '/../Php8StubsMap.php ' ;
122122 $ parts = explode ('. ' , $ updateFrom );
123+
124+ // @phpstan-ignore phpstanApi.constructor
123125 $ map = new \PHPStan \Php8StubsMap ((int ) $ parts [0 ] * 10000 + (int ) ($ parts [1 ] ?? 0 ) * 100 + (int ) ($ parts [2 ] ?? 0 ));
124126 $ classes = $ map ->classes ;
125127 $ functions = $ map ->functions ;
@@ -196,7 +198,7 @@ public function __construct(string $stubPath)
196198 $ this ->stubPath = $ stubPath ;
197199 }
198200
199- public function enterNode (Node $ node )
201+ public function enterNode (Node $ node ): ? int
200202 {
201203 if ($ node instanceof Node \Stmt \Namespace_) {
202204 // pass
@@ -457,51 +459,49 @@ private function compareStatementsInNamespace(array $oldStmts, array $newStmts,
457459 }
458460 }
459461
460- if ($ old ->stmts !== null ) {
461- $ newStmtsToSet = $ untouchedStmts ;
462- foreach ($ newMethods as $ stmt ) {
463- $ methodName = $ stmt ->name ->toLowerString ();
464- if (!array_key_exists ($ methodName , $ oldMethods )) {
465- $ stmt ->attrGroups [] = new Node \AttributeGroup ([
466- new Node \Attribute (
467- new Node \Name \FullyQualified ('Since ' ),
468- [new Node \Arg (new Node \Scalar \String_ ($ updateTo ))],
469- ),
470- ]);
471- $ newStmtsToSet [] = $ stmt ;
472- continue ;
473- }
462+ $ newStmtsToSet = $ untouchedStmts ;
463+ foreach ($ newMethods as $ stmt ) {
464+ $ methodName = $ stmt ->name ->toLowerString ();
465+ if (!array_key_exists ($ methodName , $ oldMethods )) {
466+ $ stmt ->attrGroups [] = new Node \AttributeGroup ([
467+ new Node \Attribute (
468+ new Node \Name \FullyQualified ('Since ' ),
469+ [new Node \Arg (new Node \Scalar \String_ ($ updateTo ))],
470+ ),
471+ ]);
472+ $ newStmtsToSet [] = $ stmt ;
473+ continue ;
474+ }
474475
475- foreach ($ this ->compareFunctions ($ oldMethods [$ methodName ], $ stmt , $ updateTo ) as $ functionStmt ) {
476- $ newStmtsToSet [] = $ functionStmt ;
477- }
476+ foreach ($ this ->compareFunctions ($ oldMethods [$ methodName ], $ stmt , $ updateTo ) as $ functionStmt ) {
477+ $ newStmtsToSet [] = $ functionStmt ;
478478 }
479+ }
479480
480- // todo has a method been removed?
481-
482- foreach ($ newConstants as $ stmt ) {
483- $ namesKey = implode (', ' , array_map (static fn (Node \Const_ $ const ) => $ const ->name ->toString (), $ stmt ->consts ));
484- if (!array_key_exists ($ namesKey , $ oldConstants )) {
485- $ stmt ->attrGroups [] = new Node \AttributeGroup ([
486- new Node \Attribute (
487- new Node \Name \FullyQualified ('Since ' ),
488- [new Node \Arg (new Node \Scalar \String_ ($ updateTo ))],
489- ),
490- ]);
491- $ newStmtsToSet [] = $ stmt ;
492- continue ;
493- }
481+ // todo has a method been removed?
494482
495- foreach ($ this ->compareConstants ($ oldConstants [$ namesKey ], $ stmt , $ updateTo ) as $ constantStmt ) {
496- $ newStmtsToSet [] = $ constantStmt ;
497- }
483+ foreach ($ newConstants as $ stmt ) {
484+ $ namesKey = implode (', ' , array_map (static fn (Node \Const_ $ const ) => $ const ->name ->toString (), $ stmt ->consts ));
485+ if (!array_key_exists ($ namesKey , $ oldConstants )) {
486+ $ stmt ->attrGroups [] = new Node \AttributeGroup ([
487+ new Node \Attribute (
488+ new Node \Name \FullyQualified ('Since ' ),
489+ [new Node \Arg (new Node \Scalar \String_ ($ updateTo ))],
490+ ),
491+ ]);
492+ $ newStmtsToSet [] = $ stmt ;
493+ continue ;
498494 }
499495
500- // todo has a constant been removed?
501-
502- $ old -> stmts = $ newStmtsToSet ;
496+ foreach ( $ this -> compareConstants ( $ oldConstants [ $ namesKey ], $ stmt , $ updateTo ) as $ constantStmt ) {
497+ $ newStmtsToSet [] = $ constantStmt ;
498+ }
503499 }
504500
501+ // todo has a constant been removed?
502+
503+ $ old ->stmts = $ newStmtsToSet ;
504+
505505 return [$ old ];
506506 }
507507
0 commit comments