| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Issue type | False-Positive |
| Plugin | Php Inspections (EA Extended) v3.0.9.1 |
| Language level | PHP 7.2 |
When typing this code
<?php
function view()
{
$view = array();
for($i=0;$i<1;$i++) {
$view['test'] = true;
}
include 'display_view.php';
}
PHP EA will detect "Parameter/variable is overridden, but is never used or appears outside of the scope." on this line:
$view['test'] = true;
However, the variable could be used inside the display_view.php file included below.
We should have the possibility to exclude cases like this for this inspection as they can be false positives.
For consistency, I think it could be a great idea to add an option "Ignore 'include' and 'require' statements" as in the "Undefined variable" Inspection from PHPStorm. This option would be checked by default and when checked, the Inspection behavior would remain the same. However, when unchecked, the inspection would stop detecting this Inspection when 'include' or 'require' are after an unused variable.
Thanks for your awesome work! I'm working on a projet with 10 years of code made by dozens devs who left since. I discovered PHP EA some months ago and it really did help to modernize our code and detecting old messes.
Well, true, I ran into this as well a few times, but decided to not report it, because it's dirty / a bad practise anyway and we will get rid of that remaining code soon.
But you are correct, would be better if that would be taken into account.
Thanks!
As I was saying, we have a 10 years old legacy code, we're using Inspections to help clean old stuff, detect unused code etc... We have a file with 5000+ lines of code who consist almost entirely in preparing variable and then include a small template for printers. Inspections are really useful to be sure not to break something but they're hard to use when there are false positives as well.
@orklah you can suppress this inspection for the file.
@funivan Indeed. This is what I'll do if this issue is declined. However, the file I took for my example is only one case, We have many more and they're not so binary, in some case we have code after the include, which could be in error, in some other the functions are mixed.
This is clearly not a major issue, but it could be a great functionnality for projects like mine.
@orklah: you are welcome, happy to hear that it helps to keep the legacy under control =)
I added the setting and it'll be available in the next release (somewhere in January).