| Conditions | 12 |
| Paths | 9 |
| Total Lines | 59 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 68 | public function process(File $phpcsFile, $stackPtr) |
||
| 69 | { |
||
| 70 | $this->phpCsFile = $phpcsFile; |
||
| 71 | |||
| 72 | $varRegExp = '/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/'; |
||
| 73 | |||
| 74 | $tokens = $phpcsFile->getTokens(); |
||
| 75 | $content = $tokens[$stackPtr]['content']; |
||
| 76 | |||
| 77 | $matches = array(); |
||
| 78 | |||
| 79 | preg_match_all($varRegExp, $content, $matches, PREG_OFFSET_CAPTURE); |
||
| 80 | |||
| 81 | foreach ($matches as $match) { |
||
| 82 | foreach ($match as $info) { |
||
| 83 | list($var, $pos) = $info; |
||
| 84 | |||
| 85 | if ($pos === 1 || $content[($pos - 1)] !== '{') { |
||
| 86 | if (strpos(substr($content, 0, $pos), '{') > 0 |
||
| 87 | && strpos(substr($content, 0, $pos), '}') === false |
||
| 88 | ) { |
||
| 89 | continue; |
||
| 90 | } |
||
| 91 | |||
| 92 | $lastOpeningBrace = strrpos(substr($content, 0, $pos), '{'); |
||
| 93 | if ($lastOpeningBrace !== false |
||
| 94 | && $content[($lastOpeningBrace + 1)] === '$' |
||
| 95 | ) { |
||
| 96 | $lastClosingBrace = strrpos(substr($content, 0, $pos), '}'); |
||
| 97 | |||
| 98 | if ($lastClosingBrace !== false |
||
| 99 | && $lastClosingBrace < $lastOpeningBrace |
||
| 100 | ) { |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | $fix = $this->phpCsFile->addFixableError( |
||
| 106 | sprintf( |
||
| 107 | 'must surround variable %s with { }', |
||
| 108 | $var |
||
| 109 | ), |
||
| 110 | $stackPtr, |
||
| 111 | 'NotSurroundedWithBraces' |
||
| 112 | ); |
||
| 113 | |||
| 114 | if ($fix === true) { |
||
| 115 | $correctVariable = $this->surroundVariableWithBraces( |
||
| 116 | $content, |
||
| 117 | $pos, |
||
| 118 | $var |
||
| 119 | ); |
||
| 120 | $this->fixPhpCsFile($stackPtr, $correctVariable); |
||
| 121 | } |
||
| 122 | }//end if |
||
| 123 | }//end foreach |
||
| 124 | }//end foreach |
||
| 125 | |||
| 126 | }//end process() |
||
| 127 | |||
| 168 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.