Conditions | 10 |
Paths | 10 |
Total Lines | 47 |
Code Lines | 28 |
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 |
||
45 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
46 | { |
||
47 | if ($this->supportsBelow('5.6') !== true) { |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | $tokens = $phpcsFile->getTokens(); |
||
52 | |||
53 | $ignore = array( |
||
54 | T_DOUBLE_COLON, |
||
55 | T_OBJECT_OPERATOR, |
||
56 | T_FUNCTION, |
||
57 | T_CONST, |
||
58 | ); |
||
59 | |||
60 | $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
||
61 | if (in_array($tokens[$prevToken]['code'], $ignore) === true) { |
||
62 | // Not a call to a PHP function. |
||
63 | return; |
||
64 | } |
||
65 | |||
66 | $functionLc = strtolower($tokens[$stackPtr]['content']); |
||
67 | if ($functionLc !== 'define') { |
||
68 | return; |
||
69 | } |
||
70 | |||
71 | $secondParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 2); |
||
72 | if (isset($secondParam['start'], $secondParam['end']) === false) { |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | $targetNestingLevel = 0; |
||
77 | if (isset($tokens[$secondParam['start']]['nested_parenthesis'])) { |
||
78 | $targetNestingLevel = count($tokens[$secondParam['start']]['nested_parenthesis']); |
||
79 | } |
||
80 | |||
81 | $array = $phpcsFile->findNext(array(T_ARRAY, T_OPEN_SHORT_ARRAY), $secondParam['start'], ($secondParam['end'] + 1)); |
||
82 | if ($array !== false) { |
||
83 | if ((isset($tokens[$array]['nested_parenthesis']) === false && $targetNestingLevel === 0) || count($tokens[$array]['nested_parenthesis']) === $targetNestingLevel) { |
||
84 | $phpcsFile->addError( |
||
85 | 'Constant arrays using define are not allowed in PHP 5.6 or earlier', |
||
86 | $array, |
||
87 | 'Found' |
||
88 | ); |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.