Conditions | 10 |
Paths | 19 |
Total Lines | 55 |
Code Lines | 27 |
Lines | 5 |
Ratio | 9.09 % |
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 |
||
61 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
62 | { |
||
63 | if ($this->supportsAbove('5.3') === false) { |
||
64 | return; |
||
65 | } |
||
66 | |||
67 | $tokens = $phpcsFile->getTokens(); |
||
68 | |||
69 | // Check if the variable name is in our blacklist. |
||
70 | if (in_array(substr($tokens[$stackPtr]['content'], 1), $this->deprecated, true) === false) { |
||
71 | return; |
||
72 | } |
||
73 | |||
74 | if ($this->inClassScope($phpcsFile, $stackPtr, false) === true) { |
||
75 | /* |
||
76 | * Check for class property definitions. |
||
77 | */ |
||
78 | $properties = array(); |
||
79 | try { |
||
80 | $properties = $phpcsFile->getMemberProperties($stackPtr); |
||
81 | } catch ( PHP_CodeSniffer_Exception $e) { |
||
82 | // If it's not an expected exception, throw it. |
||
83 | if ($e->getMessage() !== '$stackPtr is not a class member var') { |
||
84 | throw $e; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if (isset($properties['scope'])) { |
||
89 | // Ok, so this was a class property declaration, not our concern. |
||
90 | return; |
||
91 | } |
||
92 | |||
93 | /* |
||
94 | * Check for static usage of class properties shadowing the long arrays. |
||
95 | */ |
||
96 | $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
||
97 | if ($tokens[$prevToken]['code'] === T_DOUBLE_COLON) { |
||
98 | return; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | // Still here, so throw an error/warning. |
||
103 | $error = "The use of long predefined variables has been deprecated in 5.3%s; Found '%s'"; |
||
104 | $isError = $this->supportsAbove('5.4'); |
||
105 | $data = array( |
||
106 | ($isError ? ' and removed in 5.4' : ''), |
||
107 | $tokens[$stackPtr]['content'] |
||
108 | ); |
||
109 | |||
110 | View Code Duplication | if ($isError === true) { |
|
1 ignored issue
–
show
|
|||
111 | $phpcsFile->addError($error, $stackPtr, 'Found', $data); |
||
112 | } else { |
||
113 | $phpcsFile->addWarning($error, $stackPtr, 'Found', $data); |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 |
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.