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