Rector: Return value of PhpParser\Internal\TokenStream::getIndentationBefore() must be of the type int, null returned

Created on 20 Apr 2020  路  5Comments  路  Source: rectorphp/rector

Bug Report

| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| PHP | 7.4.5 (docker php:7.4.5-fpm-alpine) |
| Rector version | 0.7.16 (also 0.7.15) |
| Installed as | composer dependency |

When I run rector, I get the following errors:

[ERROR] Could not process "src/Entity/MyEntity.php" file, due to:                                                  
         "Call to a member function getByType() on null".
[ERROR] Could not process "src/Entity/MyOtherEntity.php" file, due to: "Return value of PhpParser\Internal\TokenStream::getIndentationBefore() must be of the type int, null          
         returned".

Possibly (probably?) related to https://github.com/rectorphp/rector/issues/1408.

During the run, I noticed some PHP warnings:

PHP Warning:  assert(): assert($itemStartPos >= 0 && $itemEndPos >= 0) failed in /srv/api/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php on line 757
Warning: assert(): assert($itemStartPos >= 0 && $itemEndPos >= 0) failed in /srv/api/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php on line 757
PHP Notice:  Undefined offset: -1 in phar:///srv/api/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php on line 183

Does this mean this is related to the php-parser instead of rector?

I tried dev-master, so php-parser is updated to the latest version. Now I get a different set of errors, which I'm not sure are related to this package. If not, then maybe my issue is already fixed on dev-master

PHP Notice:  iconv(): Wrong charset, conversion from `UTF-8' to `ASCII//TRANSLIT//IGNORE' is not allowed in /srv/api/vendor/nette/utils/src/Utils/Strings.php on line 160
Notice: iconv(): Wrong charset, conversion from `UTF-8' to `ASCII//TRANSLIT//IGNORE' is not allowed in /srv/api/vendor/nette/utils/src/Utils/Strings.php on line 160

[ERROR] Return value of Nette\Utils\Strings::toAscii() must be of the type string, bool returned

Minimal PHP Code Causing Issue

parameters:
  auto_import_names: true
  import_short_classes: false
  php_version_features: '7.4'
  symfony_container_xml_path: 'var/cache/dev/App_KernelDevDebugContainer.xml'
  paths:
    - 'src'
  exclude_paths:
    - 'src/Migrations/*'
    - 'src/Repository/*'
  sets:
    - 'php73'
    - 'php74'
  exclude_rectors:
    - 'Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector'
php vendor/bin/rector process src --dry-run

Expected Behaviour

Not to get these errors =)

Most helpful comment

nikic/php-parser dev-master fixed the issue

All 5 comments

Demo link is needed: https://getrector.org/demo

Blind shot: It might be related to docker alpine. The nette/utils might need some extension that is not installed by default, my guess mb_string but not sure

Also this is related to the latest php-parser + PHPStan. Is fixed in the last version

In what version is this fixed?

Im using rector v0.7.16 and phpstan 0.12.19

The issue regarding to iconv was indeed a Linux Alpine issue.

The other issue disappeared on dev-master, which means this is probably fixed on new release, where nikic/php-parser is update.

nikic/php-parser dev-master fixed the issue

Was this page helpful?
0 / 5 - 0 ratings