sebastianbergmann / phploc

A tool for quickly measuring the size of a PHP project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Notices

dereuromark opened this issue · comments

The tool emits notices, probably some missing defensive coding somewhere

PHP Notice: Undefined offset: 7 in phar:///.../project/phploc.phar/src/Analyser.php on line 509

Which version of PHPLOC do you use? Can you provide a minimal, self-contained piece of code that triggers the notice?

latest 6.0.2 downloaded today

It is hard to say what vendor file causes this, but I would just add a guard isset() clause in there to return early if the array key does not exist maybe.

while (\is_array($tokens[$i + 1]) && $tokens[$i + 1][0] !== \T_WHITESPACE) {

to

while (isset($tokens[$i + 1]) && \is_array($tokens[$i + 1]) && $tokens[$i + 1][0] !== \T_WHITESPACE) {

Guarding the statement with an isset() does not actually solve the issue but instead just works around it. I want to understand why we run into a situation where that element does not exist. And for that I need a minimal, self-contained, reproducing test case.

I was able to trace it down to a specific vendor package
https://github.com/spryker/code-sniffer

Sorry, but I need a single file.

@dereuromark what is the version of spryker/code-sniffer? I've tried latest (0.15.3), 0.15.0, 0.14.0 and dev-master, but no luck with reproduction the notice.

What is the PHP version you are using (should not matter, but how knows)? I've tested this on PHP 7.4.3.