selective-php / image-type

Image type (format) detection for PHP
MIT License
7 stars 4 forks source link

Using static analysis with phpstan for strpos issue #28

Closed peter279k closed 5 years ago

peter279k commented 5 years ago

As title, it seems that we use the latest stable phpstan version, but it seems that this doesn't fix the issue currently.

It's related to this phpstan issue.

peter279k commented 5 years ago

To avoid this issue, it seems that we use the strpos($bytes ?: '', 'Hasselblad')...... at this moment.

This code snippets present in the FR3 and PEF image detection.

odan commented 5 years ago

Do you see a better solutions / workaround without lowering the phpstan version and level? It thinks we can leave it as it is.

peter279k commented 5 years ago

@odan, I figure out we can consider using casting string type to solve this problem.

My approach is as follows:

?php

$files = new SplFileObject('./composer.json', 'r');

strpos((string) $files->fread(4), "php");

The original approach is as follows:

?php

$files = new SplFileObject('./composer.json', 'r');

strpos($files->fread(4) ?: "", "php");

These two approaches will be passed by php7.2 vendor/bin/phpstan analyse test.php --level=max -c phpstan.neon --no-progress command.

I think the casting string type is more readable than using ?: operator.

odan commented 5 years ago

I think the casting string type is more readable than using ?: operator.

Yes, indeed. In this case, casting to string, is fine.

peter279k commented 5 years ago

Just notice that these code snippets should change into casting string type style.

image

I think this work is about the enhancement :).

odan commented 5 years ago

Schould be fixed now.