| Conditions | 12 |
| Paths | 25 |
| Total Lines | 51 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 60 | public function processParameters(\PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionName, $parameters) |
||
| 61 | { |
||
| 62 | if (isset($parameters[2]) === false) { |
||
| 63 | return; |
||
| 64 | } |
||
| 65 | |||
| 66 | $tokens = $phpcsFile->getTokens(); |
||
| 67 | $targetParam = $parameters[2]; |
||
| 68 | $errors = array(); |
||
| 69 | |||
| 70 | for ($i = $targetParam['start']; $i <= $targetParam['end']; $i++) { |
||
| 71 | if ($tokens[$i]['code'] !== T_CONSTANT_ENCAPSED_STRING) { |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | if (strpos($tokens[$i]['content'], 'c+') !== false && $this->supportsBelow('5.2.5')) { |
||
| 76 | $errors['cplusFound'] = array( |
||
| 77 | 'c+', |
||
| 78 | '5.2.5', |
||
| 79 | $targetParam['raw'], |
||
| 80 | ); |
||
| 81 | } elseif (strpos($tokens[$i]['content'], 'c') !== false && $this->supportsBelow('5.2.5')) { |
||
| 82 | $errors['cFound'] = array( |
||
| 83 | 'c', |
||
| 84 | '5.2.5', |
||
| 85 | $targetParam['raw'], |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (strpos($tokens[$i]['content'], 'e') !== false && $this->supportsBelow('7.0.15')) { |
||
| 90 | $errors['eFound'] = array( |
||
| 91 | 'e', |
||
| 92 | '7.0.15', |
||
| 93 | $targetParam['raw'], |
||
| 94 | ); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | if (empty($errors) === true) { |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | foreach ($errors as $errorCode => $errorData) { |
||
| 103 | $phpcsFile->addError( |
||
| 104 | 'Passing "%s" as the $mode to fopen() is not supported in PHP %s or lower. Found %s', |
||
| 105 | $targetParam['start'], |
||
| 106 | $errorCode, |
||
| 107 | $errorData |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | }//end class |
||
| 112 |