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 #284

Closed LucasKovacs closed 3 years ago

LucasKovacs commented 3 years ago

I installed the newest version through composer and when ran it got the following errors

Notice: Undefined offset: 0 in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56
PHP Notice:  Undefined offset: 0 in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56

Notice: Undefined offset: 0 in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56
PHP Notice:  Undefined offset: 0 in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56

Notice: Undefined offset: 0 in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56
PHP Notice:  Undefined offset: 0 in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/bartlett/php-compatinfo/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php on line 1873
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php on line 1873
Script vendor/bin/phpcompatinfo analyser:run ./src handling the phpcompatinfo event returned with error code 255

I removed everything, vendor + .lock file and tried again. Same set of issues

Here's my composer file

{
    "require-dev": {
        "bartlett/php-compatinfo": "^5.3"
    },
    "scripts": {
        "phpcompatinfo": [
            "vendor/bin/phpcompatinfo analyser:run ./src"
        ]
    }
}

This composer file used to work fine while on 5.3

Details

llaville commented 3 years ago

Hello @LucasKovacs , Without source code analysed I can't said nothing, but it seems that you've no AST (node array) provided when I read your error.

If source code analysed is public, please provides a link.

LucasKovacs commented 3 years ago

@llaville source code can be found here

https://github.com/XGProyect/XG-Proyect-v3.x.x/tree/xgp-3.2

llaville commented 3 years ago

Thanks for the link. I've run analysis on https://github.com/XGProyect/XG-Proyect-v3.x.x/archive/v3.1.0rc.tar.gz asset and got the following report

Of course, there are some Notice but it's about empty files (as I said, no AST built). I can avoid such issue in future release !

devilbox@php-7.4.11 in /shared/backups/bartlett/php-compat-info $ bin/phpcompatinfo analyser:run tests/XGP/XG-Proyect-v3.x.x-3.1.0rc/src/ --profile --progress -vv --output
   32 11 secs File upload/public/install/update/update_302.php in progress...
Notice: Undefined offset: 0 in /shared/backups/bartlett/php-compat-info/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56
   35 11 secs File upload/public/install/update/update_common.php in progress...
Notice: Undefined offset: 0 in /shared/backups/bartlett/php-compat-info/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56

Notice: Undefined offset: 0 in /shared/backups/bartlett/php-compat-info/src/Bartlett/CompatInfo/PhpParser/NodeVisitor/ParentContextVisitor.php on line 56

Data Source Analysed

Directories                                        110
Files                                              916
Errors                                               0

Extensions Analysis

    Extension  REF        EXT min/Max     PHP min/Max
    Core       Core       5.3.0           5.4.0
    Reflection Reflection 5.0.0           5.0.0
    SimpleXML  SimpleXML  5.0.0           5.0.0
    bcmath     bcmath     4.0.0           4.0.0
    ctype      ctype      4.0.4           4.0.4
    date       date       5.2.0           5.2.0
    dom        dom        5.0.0           5.0.0
    filter     filter     0.11.0          5.0.0
    iconv      iconv      5.0.0           5.0.0
 C  intl       intl       1.0.2           5.2.4
    json       json       5.2.0           5.4.0
    mbstring   mbstring   4.0.6           4.0.6
    mysqli     mysqli     5.0.0           5.0.0
    pcre       pcre       4.0.5           4.0.5
    posix      posix      4.0.0           4.0.0
    session    session    4.0.4           4.0.4
    spl        spl        5.1.3 => 5.2.17 5.1.3
    standard   standard   7.0.2           7.0.2
 C  tidy       tidy       0.5.2           4.3.0
    xml        xml        4.0.0 => 7.1.25 4.0.0
    xmlwriter  xmlwriter  5.1.2           5.1.2
    Total [21]                            7.0.2

.... MUCH MORE CONTENT HERE ...

Conditions Analysis

    Condition                     REF  EXT min/Max PHP min/Max
    defined(BASEPATH)             user 0.1.0       4.0.0
    extension_loaded(tidy)        tidy 0.1.0       4.0.0
    function_exists(idn_to_ascii) intl 1.0.2       5.2.4
    Total [3]                                      5.2.4

Requires PHP 7.2.0 (min)

Profile results are being logged as JSON format to /tmp/61c21462-1bb3-4ab9-9c11-c6b61422cf0a-compatinfo.json

Time: 4.86 minutes, Memory: 194.00Mb
LucasKovacs commented 3 years ago

The problem is the fatal at the end, which won't allow the script to continue

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php on line 1873
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /Users/xxxx/Documents/workspace.nosync/own/project/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php on line 1873
Script vendor/bin/phpcompatinfo analyser:run ./src handling the phpcompatinfo event returned with error code 255
llaville commented 3 years ago

it depends of your platform. As I may produce report, I didn't got such issue. I suggest you to use the memory_limit = -1 directive

llaville commented 3 years ago

Will finalize the patch and you'll be notified of empty files that has no contents. In your source code that give

devilbox@php-7.4.11 in /shared/backups/bartlett/php-compat-info $ bin/phpcompatinfo ana:run tests/XGP/XG-Proyect-v3.x.x-3.1.0rc/src/

Data Source Analysed

Directories                                        110
Files                                              916
Errors                                               3

Errors found

 > File has no contents on line 1 in file /shared/backups/bartlett/php-compat-info/tests/XGP/XG-Proyect-v3.x.x-3.1.0rc/src/upload/public/install/update/update_302.php

 > File has no contents on line 1 in file /shared/backups/bartlett/php-compat-info/tests/XGP/XG-Proyect-v3.x.x-3.1.0rc/src/upload/public/install/update/update_303.php

 > File has no contents on line 1 in file /shared/backups/bartlett/php-compat-info/tests/XGP/XG-Proyect-v3.x.x-3.1.0rc/src/upload/public/install/update/update_304.php

Extensions Analysis

... MORE CONTENT
llaville commented 3 years ago

Files that are no contents (no AST built) are now notified in Errors list of report !