Uninitialized string offset: 1 in PHPLOC/Analyser.php on line 602 #22

Closed
FMaz008 opened this Issue Nov 28, 2011 · 11 comments

Comments

Projects
None yet
6 participants

FMaz008 commented Nov 28, 2011

When I run phploc against the vendor/ folder of symfony2 ( in wich I do have bundle that are not part of the standard edition ), I get about 10 PHP notice:

Uninitialized string offset: 1 in PHPLOC/Analyser.php on line 602

I've edited the PHPLOC/Analyser.php file to help debug the issue:

protected function getClassName($namespace, array $tokens, $i)
{
    $i         += 2;
    $namespaced = FALSE;
    if(!isset($tokens[$i][1])){
            var_dump($namespace, $i, $tokens[$i]);
    }
    $className  = $tokens[$i][1];

And the output is:
bool(false)
int(51)
string(1) "{"

I've also done a debug_print_backtrace:
#0 PHPLOC_Analyser->getClassName()
#1 PHPLOC_Analyser->countFile() called at [/usr/local/Cellar/php/5.3.8/lib/php/PHPLOC/Analyser.php:170]
#2 PHPLOC_Analyser->countFiles() called at [/usr/local/Cellar/php/5.3.8/lib/php/PHPLOC/TextUI/Command.php:220]
#3 PHPLOC_TextUI_Command::main() called at [/usr/local/Cellar/php/5.3.8/bin/phploc:51]

In version 1.7.1 of phploc, this is now line 611.

From a recent Jenkins run:

17:35:55 phploc:
17:35:55 [exec] phploc 1.7.1 by Sebastian Bergmann.
17:35:55 [exec]
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1. {main}() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1. {main}() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1. {main}() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1. {main}() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
17:36:40 [exec] PHP Notice: Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
17:36:40 [exec] PHP Stack trace:
17:36:40 [exec] PHP 1. {main}() /usr/local/bin/phploc:0
17:36:40 [exec] PHP 2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
17:36:40 [exec] PHP 3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
17:36:40 [exec] PHP 4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
17:36:40 [exec] PHP 5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373

cc: @sebastianbergmann

Also, phploc is reporting as 1.7,1. Doing a pear update says 1.7.2 is already installed. Removing it (and verifying that it's gone) and doing a fresh pear update still shows the same thing. I also grabbed the .phar per the instructions in the docs, and that version is reporting as 1.7.1 also. So sounds like a version string wasn't updated

Owner

sebastianbergmann commented Nov 9, 2012

I need a file that triggers this to debug the issue properly.

Hi Sebastian,

TL;DR: Couldn't isolate the file but DID find a bug with --exclude. The file causing the problem is one that should have been excluded from phploc. All of this is detailed below The --exclude bug happened somewhere after the 1.6.4 release.

Ok, I was thinking that it was throwing that output before it started processing any files. Further testing after your request for a file, shows that indeed it is something in a file throwing the code. Unfortunately, I don't have an example to provide since the error messages don't provide any info as to which file caused the error, and it's a very large tree.

Here is one thing I did find interesting however. This is the applicable config portion from my build (this is on a Symfony2 project, though that really shouldn't matter other than for directory layout informational purposes):

<project>
    <target name="phploc" description="Measure project size using PHPLOC">
        <exec executable="phploc">
            <arg value="--log-csv" />
            <arg value="${basedir}/build/logs/phploc.csv" />
            <arg value="--exclude" />
            <arg value="${basedir}/app/cache" />
            <arg value="--exclude" />
            <arg value="${basedir}/app/log" />
            <arg value="--exclude" />
            <arg value="${basedir}/vendor" />
            <arg value="--exclude" />
            <arg value="${basedir}/web/bundles" />
            <arg path="${basedir}" />
        </exec>
    </target>
</project>

This is the equivilent on the command line:

phploc --log-csv /usr/local/jenkins/jobs/cms/workspace/build/logs/phploc.csv --exclude /usr/local/jenkins/jobs/cms/workspace/app --exclude /usr/local/jenkins/jobs/cms/workspace/web --exclude /usr/local/jenkins/jobs/cms/workspace/vendor /usr/local/jenkins/jobs/cms/workspace/

Running from command line DOES give me the same error output. I started trying to isolate where it was coming from by running on individual directories. Given the exclusions above, the only applicable directory would be my src/ directory, and when running

phploc --log-csv /usr/local/jenkins/jobs/cms/workspace/build/logs/phploc.csv /usr/local/jenkins/jobs/cms/workspace/src/

It ran cleanly. So, I started running it on the other directories (i.e., the excluded directories). The error appeared when I ran it on /vendor. So, it is somewhere within the large /vendor tree (Symfony framework, Doctrine framework, various bundles etc).

That's all well and good but.... Given that vendor/ was originally part of the --exclude directives, why is phploc still parsing that directory? That would seem to be a (unrelated) phplog bug whereby excluded directories are being parsed (even if the statistics from that directory are not being counted, which , in looking at my numbers, they ARE being included).

Running with only vendors in the exclude list, produced the same thing:

[devtools root /usr/local/jenkins/jobs/cms]# phploc --exclude /usr/local/jenkins/jobs/cms/workspace/vendor/ /usr/local/jenkins/jobs/cms/workspace/
phploc 1.7.1 by Sebastian Bergmann.

PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
Directories:                                       1393
Files:                                             6332

Lines of Code (LOC):                             645349
  Cyclomatic Complexity / Lines of Code:           0.05
Comment Lines of Code (CLOC):                    186688
Non-Comment Lines of Code (NCLOC):               458661

Namespaces:                                        1134
Interfaces:                                         425
Traits:                                               8
Classes:                                           5810
  Abstract:                                         267 (4.60%)
  Concrete:                                        5543 (95.40%)
  Average Class Length (NCLOC):                      73
Methods:                                          33420
  Scope:
    Non-Static:                                   32502 (97.25%)
    Static:                                         918 (2.75%)
  Visibility:
    Public:                                       26032 (77.89%)
    Non-Public:                                    7388 (22.11%)
  Average Method Length (NCLOC):                     12
  Cyclomatic Complexity / Number of Methods:       1.73

Anonymous Functions:                                599
Functions:                                          113

Constants:                                         1225
  Global constants:                                  50
  Class constants:                                 1175

This is the directory structure:

[devtools root /usr/local/jenkins/jobs/cms]# ls workspace/
total 746
drwxr-xr-x   8 jenkins  jenkins   512B Nov  9 12:09 .git
-rw-r--r--   1 jenkins  jenkins   247B Nov  8 17:28 .gitignore
-rw-r--r--   1 jenkins  jenkins   180B Nov  8 17:14 README.md
drwxr-xr-x   6 jenkins  jenkins   512B Nov  9 12:10 app
drwxr-xr-x   2 jenkins  jenkins   512B Nov  8 17:14 bin
drwxr-xr-x   8 jenkins  jenkins   512B Nov  9 12:09 build
-rw-r--r--   1 jenkins  jenkins   840B Nov  9 12:09 build.xml
-rw-r--r--   1 jenkins  jenkins   3.6k Nov  8 17:14 composer.json
-rw-r--r--   1 jenkins  jenkins    65k Nov  8 17:14 composer.lock
-rwxr-xr-x   1 jenkins  jenkins   624k Nov  9 12:10 composer.phar
drwxr-xr-x   3 jenkins  jenkins   512B Nov  8 17:14 src
drwxr-xr-x  20 jenkins  jenkins   512B Nov  8 17:16 vendor
drwxr-xr-x   5 jenkins  jenkins   512B Nov  9 12:09 web

and running

phploc /usr/local/jenkins/jobs/cms/workspace/DIR_NAME

on any other directory there (app, bin, build, src, web) produces clean results with correct counts, or "No files found to scan" as appropriate.

As I was typing this out, I noticed that phploc was upgraded to 1.7.3. Tested with that and same results.

Important

One last test, and this may help you out. My development box is still running phploc 1.6.4. Out of curiosity, I ran this:

[cadev01 mbadolato ~/main/cms jenkins_setup]$ phploc --exclude vendor/ .
phploc 1.6.4 by Sebastian Bergmann.

Directories:                                        139
Files:                                              986

Lines of Code (LOC):                              54366
  Cyclomatic Complexity / Lines of Code:           0.06
Comment Lines of Code (CLOC):                     14598
Non-Comment Lines of Code (NCLOC):                39768

Namespaces:                                          88
Interfaces:                                          31
Classes:                                            290
  Abstract:                                           8 (2.76%)
  Concrete:                                         282 (97.24%)
  Average Class Length (NCLOC):                     120
Methods:                                           2698
  Scope:
    Non-Static:                                    2635 (97.66%)
    Static:                                          63 (2.34%)
  Visibility:
    Public:                                        1817 (67.35%)
    Non-Public:                                     881 (32.65%)
  Average Method Length (NCLOC):                     13
  Cyclomatic Complexity / Number of Methods:       1.80

Anonymous Functions:                                 12
Functions:                                           40

Constants:                                           65
  Global constants:                                   1
  Class constants:                                   64

and it runs clean, as you can see, including the actual statistic counts.

Running that EXACT same command on the exact same source tree on the box with 1.7.3:

[devtools root /usr/local/jenkins/jobs/cms/workspace (jenkins-cms-12)]# phploc --exclude vendor/ .
phploc 1.7.3 by Sebastian Bergmann.

PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
PHP Notice:  Uninitialized string offset: 1 in /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php on line 611
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /usr/local/bin/phploc:52
PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /usr/local/share/pear/SebastianBergmann/PHPLOC/TextUI/Command.php:209
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:172
PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /usr/local/share/pear/SebastianBergmann/PHPLOC/Analyser.php:373
Directories:                                       1393
Files:                                             6332

Lines of Code (LOC):                             645349
  Cyclomatic Complexity / Lines of Code:           0.05
Comment Lines of Code (CLOC):                    186688
Non-Comment Lines of Code (NCLOC):               458661

Namespaces:                                        1134
Interfaces:                                         425
Traits:                                               8
Classes:                                           5810
  Abstract:                                         267 (4.60%)
  Concrete:                                        5543 (95.40%)
  Average Class Length (NCLOC):                      73
Methods:                                          33420
  Scope:
    Non-Static:                                   32502 (97.25%)
    Static:                                         918 (2.75%)
  Visibility:
    Public:                                       26032 (77.89%)
    Non-Public:                                    7388 (22.11%)
  Average Method Length (NCLOC):                     12
  Cyclomatic Complexity / Number of Methods:       1.73

Anonymous Functions:                                599
Functions:                                          113

Constants:                                         1225
  Global constants:                                  50
  Class constants:                                 1175

So the exclusion is definitely different since 1.6.4

The box with 1.7.3:

[devtools root /usr/local/jenkins/jobs/cms/workspace (jenkins-cms-12)]# php --version
PHP 5.4.7 (cli) (built: Oct  4 2012 10:28:51)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

The box with 1.6.4:

[cadev01 mbadolato ~/main/cms jenkins_setup]$ php --version
PHP 5.4.7 (cli) (built: Oct  4 2012 11:13:25)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

There are some slight variations on the actual php and pear modules installed on each box, however. I can provide a list if that would help.

Please let me know if I can provide any other information!
--mark

cc: @sebastianbergmann

More investigation shows that there might be an issue with all of the pear programs processing arguments specified with the long (--option-name) format. I will investigate with a clean machine this weekend to see if I can duplicate the issue and isolate what pear module is causing it.

gjuric commented Feb 16, 2013

I have the same issue, a narrowed it down to this folder:

vendor/phpunit/php-code-coverage/Tests

The error is present only inside this folder, and If I remove it everything runs fine.

I am experiencing problems which are of the same sort.

phploc:
     [exec] phploc 1.7.4-12-g7be2f31 by Sebastian Bergmann.
     [exec] 
     [exec] PHP Notice:  Undefined offset: 3 in /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php on line 611
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() /var/www/mobidesk/vendor/phploc/phploc/composer/bin/phploc:0
     [exec] PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /var/www/mobidesk/vendor/phploc/phploc/composer/bin/phploc:71
     [exec] PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /var/www/mobidesk/vendor/phploc/phploc/src/TextUI/Command.php:209
     [exec] PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php:172
     [exec] PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php:373
     [exec] PHP Notice:  Undefined offset: 4 in /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php on line 617
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() /var/www/mobidesk/vendor/phploc/phploc/composer/bin/phploc:0
     [exec] PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /var/www/mobidesk/vendor/phploc/phploc/composer/bin/phploc:71
     [exec] PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /var/www/mobidesk/vendor/phploc/phploc/src/TextUI/Command.php:209
     [exec] PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php:172
     [exec] PHP   5. SebastianBergmann\PHPLOC\Analyser->getClassName() /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php:373
     [exec] PHP Notice:  Undefined offset: 11 in /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php on line 404
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() /var/www/mobidesk/vendor/phploc/phploc/composer/bin/phploc:0
     [exec] PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /var/www/mobidesk/vendor/phploc/phploc/composer/bin/phploc:71
     [exec] PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /var/www/mobidesk/vendor/phploc/phploc/src/TextUI/Command.php:209
     [exec] PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php:172
     [exec] PHP Notice:  Undefined offset: 11 in /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php on line 409
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() /var/www/mobidesk/vendor/phploc/phploc/composer/bin/phploc:0
     [exec] PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /var/www/mobidesk/vendor/phploc/phploc/composer/bin/phploc:71
     [exec] PHP   3. SebastianBergmann\PHPLOC\Analyser->countFiles() /var/www/mobidesk/vendor/phploc/phploc/src/TextUI/Command.php:209
     [exec] PHP   4. SebastianBergmann\PHPLOC\Analyser->countFile() /var/www/mobidesk/vendor/phploc/phploc/src/Analyser.php:172

Cannot investiage without a small, self-contained, reproducing test case.

After some debugging if found a very specific case.

My repo is also using pdepend, which has a file ./vendor/pdepend/pdepend/src/test/resources/files/Parser/VersionAllParser/testParserThrowsExpectedExceptionOnTokenStreamEnd.php

Which has the following code

<?php
class

Which has no class name, which is actually the function being called Analyser::getClassName. Seems like there needs to be protection against php files that have an unexpected end or aren't able to lint (php -l). Or the methods needs to be more sturdy, and be able to handle these alternative scenarios.

Owner

sebastianbergmann commented Jun 5, 2013

➜  ~  cat /tmp/test.php 
<?php
class
➜  ~  phploc /tmp/test.php
phploc 2.0-g15dbd72 by Sebastian Bergmann.

Size
  Lines of Code (LOC)                                2
  Comment Lines of Code (CLOC)                       0 (0.00%)
  Non-Comment Lines of Code (NCLOC)                  2 (100.00%)
  Logical Lines of Code (LLOC)                       0 (0.00%)
    Classes                                          0 (0.00%)
      Average Class Length                           0
      Average Method Length                          0
    Functions                                        0 (0.00%)
      Average Function Length                        0
    Not in classes or functions                      0 (0.00%)

Complexity
  Cyclomatic Complexity / LLOC                    0.00
  Cyclomatic Complexity / Number of Methods       0.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 (0.00%)
    Global Variables                                 0 (0.00%)
    Super-Global Variables                           0 (0.00%)
  Attribute Accesses                                 0
    Non-Static                                       0 (0.00%)
    Static                                           0 (0.00%)
  Method Calls                                       0
    Non-Static                                       0 (0.00%)
    Static                                           0 (0.00%)

Structure
  Namespaces                                         0
  Interfaces                                         0
  Traits                                             0
  Classes                                            1
    Abstract Classes                                 0 (0.00%)
    Concrete Classes                                 1 (100.00%)
  Methods                                            0
    Scope
      Non-Static Methods                             0 (0.00%)
      Static Methods                                 0 (0.00%)
    Visibility
      Public Method                                  0 (0.00%)
      Non-Public Methods                             0 (0.00%)
  Functions                                          0
    Named Functions                                  0 (0.00%)
    Anonymous Functions                              0 (0.00%)
  Constants                                          0
    Global Constants                                 0 (0.00%)
    Class Constants                                  0 (0.00%)

Seems that my previous test case was with an old version, composer failed to update the phploc dependency.
Below is a new test case again with an example file from the pdepend dependency (.vendor/pdepend/pdepend/src/test/resources/files/Parser/VersionAllParser/testParserThrowsExpectedExceptionForTokenStreamEnd.php
)

~ cat file.php
<?php
class testParserThrowsExpectedExceptionForTokenStreamEnd
{
        public function

~ ./vendor/bin/phploc file.php 
phploc 2.0-g3596d22 by Sebastian Bergmann.

PHP Notice:  Undefined offset: 11 in /var/www/cor/vendor/phploc/phploc/src/Analyser.php on line 460
PHP Stack trace:
PHP   1. {main}() /var/www/cor/vendor/phploc/phploc/composer/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /var/www/cor/vendor/phploc/phploc/composer/bin/phploc:71
PHP   3. SebastianBergmann\PHPLOC\TextUI\Command->run() /var/www/cor/vendor/phploc/phploc/src/TextUI/Command.php:237
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFiles() /var/www/cor/vendor/phploc/phploc/src/TextUI/Command.php:303
PHP   5. SebastianBergmann\PHPLOC\Analyser->countFile() /var/www/cor/vendor/phploc/phploc/src/Analyser.php:217
PHP Notice:  Undefined offset: 11 in /var/www/cor/vendor/phploc/phploc/src/Analyser.php on line 465
PHP Stack trace:
PHP   1. {main}() /var/www/cor/vendor/phploc/phploc/composer/bin/phploc:0
PHP   2. SebastianBergmann\PHPLOC\TextUI\Command->main() /var/www/cor/vendor/phploc/phploc/composer/bin/phploc:71
PHP   3. SebastianBergmann\PHPLOC\TextUI\Command->run() /var/www/cor/vendor/phploc/phploc/src/TextUI/Command.php:237
PHP   4. SebastianBergmann\PHPLOC\Analyser->countFiles() /var/www/cor/vendor/phploc/phploc/src/TextUI/Command.php:303
PHP   5. SebastianBergmann\PHPLOC\Analyser->countFile() /var/www/cor/vendor/phploc/phploc/src/Analyser.php:217
Size
  Lines of Code (LOC)                                5
  Comment Lines of Code (CLOC)                       0 (0.00%)
  Non-Comment Lines of Code (NCLOC)                  5 (100.00%)
  Logical Lines of Code (LLOC)                       0 (0.00%)
    Classes                                          0 (0.00%)
      Average Class Length                           0
      Average Method Length                          0
    Functions                                        0 (0.00%)
      Average Function Length                        0
    Not in classes or functions                      0 (0.00%)

Complexity
  Cyclomatic Complexity / LLOC                    0.00
  Cyclomatic Complexity / Number of Methods       0.00

Dependencies
  Global Accesses                                    0
    Global Constants                                 0 (0.00%)
    Global Variables                                 0 (0.00%)
    Super-Global Variables                           0 (0.00%)
  Attribute Accesses                                 0
    Non-Static                                       0 (0.00%)
    Static                                           0 (0.00%)
  Method Calls                                       0
    Non-Static                                       0 (0.00%)
    Static                                           0 (0.00%)

Structure
  Namespaces                                         0
  Interfaces                                         0
  Traits                                             0
  Classes                                            1
    Abstract Classes                                 0 (0.00%)
    Concrete Classes                                 1 (100.00%)
  Methods                                            0
    Scope
      Non-Static Methods                             0 (0.00%)
      Static Methods                                 0 (0.00%)
    Visibility
      Public Method                                  0 (0.00%)
      Non-Public Methods                             0 (0.00%)
  Functions                                          1
    Named Functions                                  0 (0.00%)
    Anonymous Functions                              1 (100.00%)
  Constants                                          0
    Global Constants                                 0 (0.00%)
    Class Constants                                  0 (0.00%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment