Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding unused variables in CakePHP views

Currently, I am using NetBeans IDE and it has a very nice feature which shows if a variable is defined but is not used in its scope. This works very nicely if you have bunch of old code, and you are trying to remove the dead bits from it.

Is there a tool/service/anything, which would do the same thing however which would find variables which are set in the controller but then not used in a view. It does not have to be fully automatic.

For example if you have the following in your controller:

$this->set(array(
     'variable1' => $variable1,
     'variable2' => $variable2
)); 

And the view looks like this:

<p>Peter ate <?php echo $variable1; ?> apples.

It would highlight or in any other way identify variable2 (given that it is not used in layout as well).

like image 440
gintas Avatar asked Nov 08 '12 18:11

gintas


1 Answers

Try running PHP Mess Detector on your codebase.

There is even a Netbeans plugin for that. Just don't run it on CakePHP source itself, or you will get a clear understanding how horribly broken it actually is.

Might be counterproductive. And cause you a cognitive dissonance of religious nature.

like image 51
tereško Avatar answered Sep 22 '22 16:09

tereško