llaville / php-compatinfo

Library that find out the minimum version and the extensions required for a piece of code to run
https://llaville.github.io/php-compatinfo/7.1/
Other
371 stars 21 forks source link

Errors while running on empty files - phtml #285

Closed BenediktAllendorf closed 3 years ago

BenediktAllendorf commented 3 years ago

PHP Notice: Undefined offset: 0 appears here: https://github.com/llaville/php-compat-info/blob/master/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php#L56

For me, adding an isset() check fixed this :)

llaville commented 3 years ago

Please, specify context of execution ?

BenediktAllendorf commented 3 years ago

Sorry, it happens when running phpcompatinfo analyser:run $dir


PHP   1. {main}() vendor/bartlett/php-compatinfo/bin/phpcompatinfo:0
PHP   2. Bartlett\CompatInfo\Console\Application->run() vendor/bartlett/php-compatinfo/bin/phpcompatinfo:27
PHP   3. Bartlett\CompatInfo\Console\Application->run() vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Console/Application.php:192
PHP   4. Bartlett\CompatInfo\Console\Application->doRun() vendor/symfony/console/Application.php:142
PHP   5. Bartlett\CompatInfo\Console\Application->doRun() vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Console/Application.php:217
PHP   6. Bartlett\CompatInfo\Console\Application->doRunCommand() vendor/symfony/console/Application.php:266
PHP   7. Bartlett\CompatInfo\Console\Command->run() vendor/symfony/console/Application.php:938
PHP   8. Bartlett\CompatInfo\Console\CommandFactory->Bartlett\CompatInfo\Console\{closure:vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Console/CommandFactory.php:256-392}() vendor/symfony/console/Command/Command.php:256
PHP   9. call_user_func_array:{vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Console/CommandFactory.php:322}() vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Console/CommandFactory.php:322
PHP  10. Bartlett\CompatInfo\Api\Analyser->run() vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Console/CommandFactory.php:322
PHP  11. Bartlett\CompatInfo\Api\Analyser->request() vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Api/Analyser.php:42
PHP  12. Bartlett\Reflect\Client\LocalClient->request() vendor/bartlett/php-reflect/src/Bartlett/Reflect/Api/BaseApi.php:73
PHP  13. call_user_func_array:{vendor/bartlett/php-reflect/src/Bartlett/Reflect/Client/LocalClient.php:87}() vendor/bartlett/php-reflect/src/Bartlett/Reflect/Client/LocalClient.php:87
PHP  14. Bartlett\CompatInfo\Api\V5\Analyser->run() vendor/bartlett/php-reflect/src/Bartlett/Reflect/Client/LocalClient.php:87
PHP  15. Bartlett\CompatInfo\Api\V5\Parser->parse() vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Api/V5/Analyser.php:88
PHP  16. PhpParser\NodeTraverser->traverse() vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/Api/V5/Parser.php:132
PHP  17. Bartlett\CompatInfo\PhpParser\NodeVisitor\ParentContextVisitor->beforeTraverse() vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:86```
llaville commented 3 years ago

It's occurs when $dir has no valid php files contents (all are empty). Please check-in your data source !

i.e: with data source (single or multiple files) are empty my-empty-data-source.php

<?php

and run command bin/phpcompatinfo analyser:run my-empty-data-source.php we got

Notice: Undefined offset: 0 in src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56

Data Source Analysed

Directories                                          1
Files                                                1
Errors                                               0

Extensions Analysis

    Extension REF  EXT min/Max PHP min/Max
    Core      Core             4.0.0
    Total [1]                  4.0.0

Namespaces Analysis

    Namespace REF  EXT min/Max PHP min/Max
              Core             4.0.0
    Total [1]                  4.0.0

No interface found

No trait found

No class found

No generator found

No function found

No constant found

No condition found

Requires PHP 4.0.0 (min)
BenediktAllendorf commented 3 years ago

Yes, almost. I tracked down one notice to a (completely) empty *.phtml file used as a template somewhere else.

Shouldn't that be allowed (and therefore, not throw a notice)? I'm running this on legacy code; there are probably a few more cases like this.

llaville commented 3 years ago

I've already solved/fixed this issue (see #284) But it was on *.php files an not *.phtml Perharps something to fix : yes I found it !

llaville commented 3 years ago

For upcoming bugfix release 5.4.2 with phar distribution automation (#270)

BenediktAllendorf commented 3 years ago

Ah, sorry I didn't check closed issues before. Thanks for your quick response :+1:

llaville commented 3 years ago

If source code is open source, can you provide a link; I've run test again with current code on master branch, and get expected results (solved in #284)

Data Source Analysed

Directories                                          1
Files                                                2
Errors                                               2

Errors found

 > File has no contents on line 1 in file /var/log/php/dummy.phtml

 > File has no contents on line 1 in file /var/log/php/dummy.php

// and more ...
llaville commented 3 years ago

Only 3 extensions are catch : see https://github.com/llaville/php-compat-info/blob/master/src/Bartlett/CompatInfo/Api/V5/SourceProvider.php#L57

llaville commented 3 years ago

@BenediktAllendorf Is the latest version of branch master solve your issue ? Waiting your feedback !

BenediktAllendorf commented 3 years ago

Yes, I just checked and I don't see notices anymore! :)