sebastianbergmann / phploc

A tool for quickly measuring the size of a PHP project.
BSD 3-Clause "New" or "Revised" License
2.34k stars 167 forks source link

Notices #208

Closed dereuromark closed 4 years ago

dereuromark commented 4 years ago

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

sebastianbergmann commented 4 years ago

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

dereuromark commented 4 years ago

latest 6.0.2 downloaded today

dereuromark commented 4 years ago

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.

dereuromark commented 4 years ago
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) {
sebastianbergmann commented 4 years ago

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.

dereuromark commented 4 years ago

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

sebastianbergmann commented 4 years ago

Sorry, but I need a single file.

kubawerlos commented 4 years ago

@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.