Conditions | 10 |
Paths | 10 |
Total Lines | 50 |
Code Lines | 23 |
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 |
||
56 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
57 | { |
||
58 | if ($this->supportsAbove('7.1') === false) { |
||
59 | return; |
||
60 | } |
||
61 | |||
62 | $tokens = $phpcsFile->getTokens(); |
||
63 | $functionNameLc = strtolower($tokens[$stackPtr]['content']); |
||
64 | |||
65 | // Bow out if not one of the functions we're targetting. |
||
66 | if ( isset($this->functions[$functionNameLc]) === false ) { |
||
67 | return; |
||
68 | } |
||
69 | |||
70 | // Get the options parameter in the function call. |
||
71 | $optionsParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->functions[$functionNameLc]); |
||
72 | if ($optionsParam === false) { |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | $stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $optionsParam['start'], $optionsParam['end'] + 1); |
||
77 | if ($stringToken === false) { |
||
78 | // No string token found in the options parameter, so skip it (e.g. variable passed in). |
||
79 | return; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Get the content of any string tokens in the options parameter and remove the quotes. |
||
84 | */ |
||
85 | $options = trim($tokens[$stringToken]['content'], '\'"'); |
||
86 | if ($stringToken !== $optionsParam['end']) { |
||
87 | while ($stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stringToken + 1, $optionsParam['end'] + 1)) { |
||
88 | if ($tokens[$stringToken]['code'] === T_CONSTANT_ENCAPSED_STRING) { |
||
89 | $options .= trim($tokens[$stringToken]['content'], '\'"'); |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | |||
94 | if (strpos($options, 'e') !== false) { |
||
95 | $error = 'The Mbstring regex "e" modifier is deprecated since PHP 7.1.'; |
||
96 | |||
97 | // The alternative mb_ereg_replace_callback() function is only available since 5.4.1 |
||
98 | if ($this->supportsBelow('5.4.1') === false) { |
||
99 | $error .= ' Use mb_ereg_replace_callback() instead (PHP 5.4.1+).'; |
||
100 | } |
||
101 | |||
102 | $phpcsFile->addError($error, $stackPtr, 'Found'); |
||
103 | } |
||
104 | |||
105 | }//end process() |
||
106 | |||
108 |