Phpinsights: Undefined offset: 0 | Fatal error: Uncaught TypeError: Argument 2 passed to SlevomatCodingStandard\Helpers\UseStatementHelper::getUseStatementPointers() must be of the type int, null given

Created on 15 May 2019  路  19Comments  路  Source: nunomaduro/phpinsights

Tried to run it on a Laravel app. Got this fatal error:

 605/910 [鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻戔枒鈻戔枒鈻戔枒鈻戔枒鈻戔枒]  66%PHP Notice:  Undefined offset: 0 in /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 147

Notice: Undefined offset: 0 in /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 147
PHP Fatal error:  Uncaught TypeError: Argument 2 passed to SlevomatCodingStandard\Helpers\UseStatementHelper::getUseStatementPointers() must be of the type int, null given, called in /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 149 and defined in /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php:193
Stack trace:
#0 /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(149): SlevomatCodingStandard\Helpers\UseStatementHelper::getUseStatementPointers(Object(NunoMaduro\PhpInsights\Domain\File), NULL)
#1 /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(111): SlevomatCodingStandard\Helpers\UseStatementHelper::getFileUseStatements(Object(NunoMaduro\PhpInsights\Domain\File))
#2 /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/PHP/OptimizedFunctions in /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 193

Fatal error: Uncaught TypeError: Argument 2 passed to SlevomatCodingStandard\Helpers\UseStatementHelper::getUseStatementPointers() must be of the type int, null given, called in /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 149 and defined in /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php:193
Stack trace:
#0 /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(149): SlevomatCodingStandard\Helpers\UseStatementHelper::getUseStatementPointers(Object(NunoMaduro\PhpInsights\Domain\File), NULL)
#1 /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(111): SlevomatCodingStandard\Helpers\UseStatementHelper::getFileUseStatements(Object(NunoMaduro\PhpInsights\Domain\File))
#2 /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/PHP/OptimizedFunctions in /Users/filipac/.composer/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 193
bug help wanted

All 19 comments

Same issue. When running with verbose -v option I see that problem happens when tool hits certain layout.blade.php file.

I had a look through the slevomat/coding-standard package code, and this appears to be to do with php files which do not contain a full opening tag <?php.

I ran insights and found it failed on a template file of mine which contained a short <?= tag, but no full tag, and it failed with this error. I then added a full tag at the start of the file and then closed it immediately (an empty php block) and insights then failed with the same error on the next template it found.

Yes, short tag is likely explanation.
In my case template contained some legacy spaghetti code such as:
<?=(preg_match(PRIVILEGES['something'],$user['privileges'])?'<a href="..">aa</a>':'')?>

Does this tool understand .blade.php files anyway? I could not get my head around if there is a way to exclude some file name patterns / directories. If not, there should be.

The folder resources is ignored on the Laravel preset, so your blade views should be ignored. No?

Oh, sorry. My project is not Laravel, just blade template component, so the path is different.
I will have to learn how to create project settings/presets. :)

You just have to: cp vendor/nunomaduro/phpinsights/stubs/config.php phpinsights.php, than add the blade folder to the exclude key.

Actually, we should exclude all *.blade.php extensions. Can someone do a pull request on this? Here is the file: https://github.com/nunomaduro/phpinsights/blob/master/src/Infrastructure/Repositories/LocalFilesRepository.php

Don't forget to add tests on this.

For me it was jquery.repeater in node_modules. Luckily I don't really need it so just removed it.

@TheFrankman Hmm that's weird, we should be ignoring node_modules.

@olivernybroe I wouldn't concern yourself too much with it, It might be down to a theme that we are importing, it's a rather unusual laravel installation.

This issue has been fixed on the version v1.8.1.

位 php artisan insights
?[2K 53/65 [======================>-----]  81%
  ?[41;1m Symfony\Component\Debug\Exception\FatalThrowableError ?[49;22m : ?[33mArgument 1 passed to NunoMaduro\PhpInsights\Doma
in\File::resolveFullyQualifiedCode() must be of the type string, int given, called in C:\Users\jadam\bsgup\vendor\nunomaduro\php
insights\src\Domain\File.php on line 191?[39m

  at ?[32mC:\Users\jadam\bsgup\vendor\nunomaduro\phpinsights\src\Domain\File.php?[39m:?[32m222?[39m
    218|      * @param  string  $sniffClassOrCode
    219|      *
    220|      * @return string
    221|      */
  > 222|     private function resolveFullyQualifiedCode(string $sniffClassOrCode): string
    223|     {
    224|         if (class_exists($sniffClassOrCode)) {
    225|             return $sniffClassOrCode;
    226|         }

  ?[33mException trace:?[39m

  ?[36m1   ?[39m?[33mNunoMaduro\PhpInsights\Domain\File::resolveFullyQualifiedCode()?[39m
      ?[32mC:\Users\jadam\bsgup\vendor\nunomaduro\phpinsights\src\Domain\File.php?[39m:?[32m191?[39m

  ?[36m2   ?[39m?[33mNunoMaduro\PhpInsights\Domain\File::addMessage("Unparsable php code: syntax error or wrong phpdocs.", [])?[
39m
      ?[32mC:\Users\jadam\bsgup\vendor\squizlabs\php_codesniffer\src\Files\File.php?[39m:?[32m663?[39m

  ?[32mPlease use the argument ?[39m?[31m-v?[39m?[32m to see more details.?[39m

^ I hit the same error as @jadamec after updating to 1.8.1

@jadamec @michaeldyrynda Can you try again with v1.9.0?

@jadamec @michaeldyrynda Can you try again with v1.9.0?

Works now, great! Thank you.

I did get a notice with 1.9, but it finished running.

@michaeldyrynda Could you share the notice, having some difficulties reproducing it.

PHP Notice: Undefined offset: 0 in /Users/mdyrynda/code/crm/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 147

@michaeldyrynda Thanks. Found the cause.
PR #253 should silence the php messages

Was this page helpful?
0 / 5 - 0 ratings