aik099 / CodingStandard

The PHP_CodeSniffer coding standard I'm using on all of my projects
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Create function parameter assignment sniff #104

Open aik099 opened 5 years ago

aik099 commented 5 years ago

Idea of the sniff is to locate function/method parameter that's value is replaced within the method. This is bad idea, because any code that reads parameter value expects original value to be retrieved, but instead is getting last modified value version.

Implementation plan:

  1. listen for T_FUNCTION token
  2. get parameters of that function, that aren't passed by reference
  3. lookup names of these parameters in function body and T_WHITESPACE (optional) + assignment tokens after it

P.S. The $$var code won't be supported, because it's hard to trace back statically.

Examples

function functionName($param1, &$param2)
{
    $param1 = 'new value' . $param1; // not allowed
    $param2 = 'new value'; // allowed, because value is passed by reference
}