Skip to content

When running MultipleClassFileToPsr4ClassesRector on multiple files: "Return value of PhpParser\Internal\TokenStream::getIndentationBefore() must be of the type int, null returned". #1408

@JanMikes

Description

@JanMikes

Command:

vendor/bin/rector process --config config/rector/psr-4-classes-split.yaml src

Config:

services:
    Rector\Rector\Psr4\MultipleClassFileToPsr4ClassesRector: ~

parameters:
    exclude_paths:
        - '**/template.php'

When i run it separately file by file, it works.

Here is call stack (when running with -vvv):

Fatal error: Uncaught TypeError: Return value of PhpParser\Internal\TokenStream::getIndentationBefore() must be of the type int, null returned in /project/vendor/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php:192
Stack trace:
#0 /rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php(763): PhpParser\Internal\TokenStream->getIndentationBefore(17)
#1 /rector/src/PhpParser/Printer/BetterStandardPrinter.php(87): PhpParser\PrettyPrinterAbstract->pArray(Array, Array, 12, 0, 'stmts', NULL, '')
#2 /rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php(573): Rector\PhpParser\Printer\BetterStandardPrinter->pArray(Array, Array, 12, 0, 'stmts', NULL, '\n')
#3 /rector/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php(867): PhpParser\PrettyPrinterAbstract->p(Object(PhpParser\Node\Stmt\Class_), true)
#4 /rector/src/PhpParser/Printer/BetterStandardPrinter.php(87): PhpParser\PrettyPrinterAbstract->pArray(Array, Array, 5, 0, 'stmts', NULL, '')
#5 /rector/vendor/nikic/php-parser/lib/Ph in /project/vendor/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php on line 192

I noticed it stops processing on file ARES.php which contains 3 classes. But when i run it only on this file it splits it correctly.

In /src there are 600 files and i got following errors when running on whole directory:

~/Sites/klarka  jm/psr-4-libs-to-src-2-split-classes ✗                                                                                                                                                                            13m ⚑  ⍉
▶ docker run -v $(pwd):/project gitlab.devklarka.cz:5000/infrastructure/web-development/rector:latest process --autoload-file /project/vendor/autoload.php --config /project/config/rector/psr-4-classes-split.yaml /project/src
Rector No version set (parsed as 1.0.0)@
Config file: /project/config/rector/psr-4-classes-split.yaml

   0/588 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
  58/588 [▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░]   9%
 116/588 [▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░]  19%
 174/588 [▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░]  29%
 232/588 [▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░]  39%
 290/588 [▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░]  49%
 348/588 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░]  59%
 406/588 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░]  69%
 464/588 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░]  78%
 522/588 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░]  88%
 580/588 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░]  98%
 588/588 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 [ERROR] Could not process "/project/src/ARES.php" file, due to:                
         "Return value of PhpParser\Internal\TokenStream::getIndentationBefore()
         must be of the type int, null returned".                                      

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions