| Conditions | 10 | 
| Paths | 4 | 
| Total Lines | 121 | 
| Code Lines | 80 | 
| 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 | ||
| 75 | public function process(File $phpcsFile, $stackPtr) | ||
| 76 |     { | ||
| 77 | $docCommentTags = array( | ||
| 78 | '@param' => 1, | ||
| 79 | '@return' => 1, | ||
| 80 | '@throws' => 1, | ||
| 81 | '@var' => 2, | ||
| 82 | ); | ||
| 83 | $scanTokens = array( | ||
| 84 | T_NS_SEPARATOR, | ||
| 85 | T_DOC_COMMENT_OPEN_TAG, | ||
| 86 | ); | ||
| 87 | |||
| 88 | $tokens = $phpcsFile->getTokens(); | ||
| 89 | $useStatements = $this->getUseStatements($phpcsFile, 0, ($stackPtr - 1)); | ||
| 90 | $namespace = $this->getNamespace($phpcsFile, 0, ($stackPtr - 1)); | ||
| 91 | |||
| 92 | $nsSep = $phpcsFile->findNext($scanTokens, ($stackPtr + 1)); | ||
| 93 | |||
| 94 |         while ($nsSep !== false) { | ||
| 95 | $nsSep = (int) $nsSep; | ||
| 96 | |||
| 97 | $classNameEnd = $phpcsFile->findNext( | ||
| 98 | $this->classNameTokens, | ||
| 99 | $nsSep, | ||
| 100 | null, | ||
| 101 | true | ||
| 102 | ); | ||
| 103 | |||
| 104 |             if ($tokens[$nsSep]['code'] === T_NS_SEPARATOR) { | ||
| 105 |                 if ($tokens[($nsSep - 1)]['code'] === T_STRING) { | ||
| 106 | --$nsSep; | ||
| 107 | } | ||
| 108 | |||
| 109 | $className = $phpcsFile->getTokensAsString( | ||
| 110 | $nsSep, | ||
| 111 | ($classNameEnd - $nsSep) | ||
| 112 | ); | ||
| 113 | |||
| 114 | $this->checkShorthandPossible( | ||
| 115 | $phpcsFile, | ||
| 116 | $useStatements, | ||
| 117 | $className, | ||
| 118 | $namespace, | ||
| 119 | $nsSep, | ||
| 120 | ($classNameEnd - 1), | ||
| 121 | false | ||
| 122 | ); | ||
| 123 |             } else { | ||
| 124 | // Doc comment block. | ||
| 125 |                 foreach ($tokens[$nsSep]['comment_tags'] as $tag) { | ||
| 126 | $content = $tokens[$tag]['content']; | ||
| 127 |                     if (array_key_exists($content, $docCommentTags) === false) { | ||
| 128 | continue; | ||
| 129 | } | ||
| 130 | |||
| 131 | $next = ($tag + 1); | ||
| 132 | // PHP Code Sniffer will magically add T_DOC_COMMENT_CLOSE_TAG with empty string content. | ||
| 133 | $lineEnd = $phpcsFile->findNext( | ||
| 134 | array( | ||
| 135 | T_DOC_COMMENT_CLOSE_TAG, | ||
| 136 | T_DOC_COMMENT_STAR, | ||
| 137 | ), | ||
| 138 | $next | ||
| 139 | ); | ||
| 140 | |||
| 141 | $docCommentStringPtr = $phpcsFile->findNext( | ||
| 142 | array(T_DOC_COMMENT_STRING), | ||
| 143 | $next, | ||
| 144 | (int) $lineEnd | ||
| 145 | ); | ||
| 146 | |||
| 147 |                     if ($docCommentStringPtr === false) { | ||
| 148 | continue; | ||
| 149 | } | ||
| 150 | |||
| 151 | $docCommentStringPtr = (int) $docCommentStringPtr; | ||
| 152 | |||
| 153 | $docLine = $tokens[$docCommentStringPtr]['content']; | ||
| 154 | |||
| 155 | $docLineTokens = preg_split( | ||
| 156 | '/\s+/', | ||
| 157 | $docLine, | ||
| 158 | -1, | ||
| 159 | PREG_SPLIT_NO_EMPTY | ||
| 160 | ); | ||
| 161 | $docLineTokens = array_slice( | ||
| 162 | $docLineTokens, | ||
| 163 | 0, | ||
| 164 | $docCommentTags[$content] | ||
| 165 | ); | ||
| 166 |                     foreach ($docLineTokens as $docLineToken) { | ||
| 167 | $typeTokens = preg_split( | ||
| 168 | '/\|/', | ||
| 169 | $docLineToken, | ||
| 170 | -1, | ||
| 171 | PREG_SPLIT_NO_EMPTY | ||
| 172 | ); | ||
| 173 |                         foreach ($typeTokens as $typeToken) { | ||
| 174 |                             if (true === in_array($typeToken, $useStatements)) { | ||
| 175 | continue; | ||
| 176 | } | ||
| 177 | |||
| 178 | $this->checkShorthandPossible( | ||
| 179 | $phpcsFile, | ||
| 180 | $useStatements, | ||
| 181 | $typeToken, | ||
| 182 | $namespace, | ||
| 183 | $docCommentStringPtr, | ||
| 184 | $docCommentStringPtr, | ||
| 185 | true | ||
| 186 | ); | ||
| 187 | }//end foreach | ||
| 188 | }//end foreach | ||
| 189 | }//end foreach | ||
| 190 | }//end if | ||
| 191 | |||
| 192 | $nsSep = $phpcsFile->findNext($scanTokens, ($classNameEnd + 1)); | ||
| 193 | }//end while | ||
| 194 | |||
| 195 | }//end process() | ||
| 196 | |||
| 414 | 
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.