| Conditions | 10 |
| Paths | 19 |
| Total Lines | 42 |
| Code Lines | 25 |
| 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 |
||
| 113 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
| 114 | { |
||
| 115 | $interfaces = $this->findImplementedInterfaceNames($phpcsFile, $stackPtr); |
||
| 116 | |||
| 117 | if (is_array($interfaces) === false || $interfaces === array()) { |
||
| 118 | return; |
||
| 119 | } |
||
| 120 | |||
| 121 | $tokens = $phpcsFile->getTokens(); |
||
| 122 | $checkMethods = false; |
||
| 123 | |||
| 124 | if(isset($tokens[$stackPtr]['scope_closer'])) { |
||
| 125 | $checkMethods = true; |
||
| 126 | $scopeCloser = $tokens[$stackPtr]['scope_closer']; |
||
| 127 | } |
||
| 128 | |||
| 129 | foreach ($interfaces as $interface) { |
||
| 130 | $lcInterface = strtolower($interface); |
||
| 131 | if (isset($this->newInterfaces[$lcInterface]) === true) { |
||
| 132 | $this->addError($phpcsFile, $stackPtr, $interface); |
||
| 133 | } |
||
| 134 | |||
| 135 | if ($checkMethods === true && isset($this->unsupportedMethods[$lcInterface]) === true) { |
||
| 136 | $nextFunc = $stackPtr; |
||
| 137 | while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) { |
||
| 138 | $funcNamePos = $phpcsFile->findNext(T_STRING, $nextFunc); |
||
| 139 | $funcName = strtolower($tokens[$funcNamePos]['content']); |
||
| 140 | |||
| 141 | if (isset($this->unsupportedMethods[$lcInterface][$funcName]) === true) { |
||
| 142 | $error = 'Classes that implement interface %s do not support the method %s(). See %s'; |
||
| 143 | $data = array( |
||
| 144 | $interface, |
||
| 145 | $tokens[$funcNamePos]['content'], |
||
| 146 | $this->unsupportedMethods[$lcInterface][$funcName], |
||
| 147 | ); |
||
| 148 | $phpcsFile->addError($error, $funcNamePos, 'UnsupportedMethod', $data); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | }//end process() |
||
| 155 | |||
| 195 |
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.