Conditions | 11 |
Paths | 23 |
Total Lines | 52 |
Code Lines | 31 |
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 |
||
109 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
110 | { |
||
111 | $interfaces = $this->findImplementedInterfaceNames($phpcsFile, $stackPtr); |
||
112 | |||
113 | if (is_array($interfaces) === false || $interfaces === array()) { |
||
114 | return; |
||
115 | } |
||
116 | |||
117 | $tokens = $phpcsFile->getTokens(); |
||
118 | $checkMethods = false; |
||
119 | |||
120 | if(isset($tokens[$stackPtr]['scope_closer'])) { |
||
121 | $checkMethods = true; |
||
122 | $scopeCloser = $tokens[$stackPtr]['scope_closer']; |
||
123 | } |
||
124 | |||
125 | foreach ($interfaces as $interface) { |
||
126 | $interfaceLc = strtolower($interface); |
||
127 | |||
128 | if (isset($this->newInterfaces[$interfaceLc]) === true) { |
||
129 | $itemInfo = array( |
||
130 | 'name' => $interface, |
||
131 | 'nameLc' => $interfaceLc, |
||
132 | ); |
||
133 | $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
||
134 | } |
||
135 | |||
136 | if ($checkMethods === true && isset($this->unsupportedMethods[$interfaceLc]) === true) { |
||
137 | $nextFunc = $stackPtr; |
||
138 | while (($nextFunc = $phpcsFile->findNext(T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) { |
||
139 | $funcName = $phpcsFile->getDeclarationName($nextFunc); |
||
140 | $funcNameLc = strtolower($funcName); |
||
141 | if ($funcNameLc === '') { |
||
142 | continue; |
||
143 | } |
||
144 | |||
145 | if (isset($this->unsupportedMethods[$interfaceLc][$funcNameLc]) === true) { |
||
146 | $error = 'Classes that implement interface %s do not support the method %s(). See %s'; |
||
147 | $errorCode = $this->stringToErrorCode($interface).'UnsupportedMethod'; |
||
148 | $data = array( |
||
149 | $interface, |
||
150 | $funcName, |
||
151 | $this->unsupportedMethods[$interfaceLc][$funcNameLc], |
||
152 | ); |
||
153 | |||
154 | $phpcsFile->addError($error, $nextFunc, $errorCode, $data); |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | } |
||
159 | |||
160 | }//end process() |
||
161 | |||
188 |
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.