Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like CallFinder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CallFinder, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 5 | class CallFinder  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 6 | { | 
            ||
| 7 | private static $ignore = array(  | 
            ||
| 8 | T_CLOSE_TAG => true,  | 
            ||
| 9 | T_COMMENT => true,  | 
            ||
| 10 | T_DOC_COMMENT => true,  | 
            ||
| 11 | T_INLINE_HTML => true,  | 
            ||
| 12 | T_OPEN_TAG => true,  | 
            ||
| 13 | T_OPEN_TAG_WITH_ECHO => true,  | 
            ||
| 14 | T_WHITESPACE => true,  | 
            ||
| 15 | );  | 
            ||
| 16 | |||
| 17 | /**  | 
            ||
| 18 | * Things we need to do specially for operator tokens:  | 
            ||
| 19 | * - Refuse to strip spaces around them  | 
            ||
| 20 | * - Wrap the access path in parentheses if there  | 
            ||
| 21 | * are any of these in the final short parameter.  | 
            ||
| 22 | */  | 
            ||
| 23 | private static $operator = array(  | 
            ||
| 24 | T_AND_EQUAL => true,  | 
            ||
| 25 | T_BOOLEAN_AND => true,  | 
            ||
| 26 | T_BOOLEAN_OR => true,  | 
            ||
| 27 | T_ARRAY_CAST => true,  | 
            ||
| 28 | T_BOOL_CAST => true,  | 
            ||
| 29 | T_CLONE => true,  | 
            ||
| 30 | T_CONCAT_EQUAL => true,  | 
            ||
| 31 | T_DEC => true,  | 
            ||
| 32 | T_DIV_EQUAL => true,  | 
            ||
| 33 | T_DOUBLE_CAST => true,  | 
            ||
| 34 | T_INC => true,  | 
            ||
| 35 | T_INCLUDE => true,  | 
            ||
| 36 | T_INCLUDE_ONCE => true,  | 
            ||
| 37 | T_INSTANCEOF => true,  | 
            ||
| 38 | T_INT_CAST => true,  | 
            ||
| 39 | T_IS_EQUAL => true,  | 
            ||
| 40 | T_IS_GREATER_OR_EQUAL => true,  | 
            ||
| 41 | T_IS_IDENTICAL => true,  | 
            ||
| 42 | T_IS_NOT_EQUAL => true,  | 
            ||
| 43 | T_IS_NOT_IDENTICAL => true,  | 
            ||
| 44 | T_IS_SMALLER_OR_EQUAL => true,  | 
            ||
| 45 | T_LOGICAL_AND => true,  | 
            ||
| 46 | T_LOGICAL_OR => true,  | 
            ||
| 47 | T_LOGICAL_XOR => true,  | 
            ||
| 48 | T_MINUS_EQUAL => true,  | 
            ||
| 49 | T_MOD_EQUAL => true,  | 
            ||
| 50 | T_MUL_EQUAL => true,  | 
            ||
| 51 | T_NEW => true,  | 
            ||
| 52 | T_OBJECT_CAST => true,  | 
            ||
| 53 | T_OR_EQUAL => true,  | 
            ||
| 54 | T_PLUS_EQUAL => true,  | 
            ||
| 55 | T_REQUIRE => true,  | 
            ||
| 56 | T_REQUIRE_ONCE => true,  | 
            ||
| 57 | T_SL => true,  | 
            ||
| 58 | T_SL_EQUAL => true,  | 
            ||
| 59 | T_SR => true,  | 
            ||
| 60 | T_SR_EQUAL => true,  | 
            ||
| 61 | T_STRING_CAST => true,  | 
            ||
| 62 | T_UNSET_CAST => true,  | 
            ||
| 63 | T_XOR_EQUAL => true,  | 
            ||
| 64 | '!' => true,  | 
            ||
| 65 | '%' => true,  | 
            ||
| 66 | '&' => true,  | 
            ||
| 67 | '*' => true,  | 
            ||
| 68 | '+' => true,  | 
            ||
| 69 | '-' => true,  | 
            ||
| 70 | '.' => true,  | 
            ||
| 71 | '/' => true,  | 
            ||
| 72 | ':' => true,  | 
            ||
| 73 | '<' => true,  | 
            ||
| 74 | '=' => true,  | 
            ||
| 75 | '>' => true,  | 
            ||
| 76 | '?' => true,  | 
            ||
| 77 | '^' => true,  | 
            ||
| 78 | '|' => true,  | 
            ||
| 79 | '~' => true,  | 
            ||
| 80 | );  | 
            ||
| 81 | |||
| 82 | private static $strip = array(  | 
            ||
| 83 |         '(' => true, | 
            ||
| 84 | ')' => true,  | 
            ||
| 85 | '[' => true,  | 
            ||
| 86 | ']' => true,  | 
            ||
| 87 |         '{' => true, | 
            ||
| 88 | '}' => true,  | 
            ||
| 89 | T_OBJECT_OPERATOR => true,  | 
            ||
| 90 | T_DOUBLE_COLON => true,  | 
            ||
| 91 | T_NS_SEPARATOR => true,  | 
            ||
| 92 | );  | 
            ||
| 93 | |||
| 94 | private static $identifier = array(  | 
            ||
| 95 | T_DOUBLE_COLON => true,  | 
            ||
| 96 | T_STRING => true,  | 
            ||
| 97 | T_NS_SEPARATOR => true,  | 
            ||
| 98 | );  | 
            ||
| 99 | |||
| 100 | public static function getFunctionCalls($source, $line, $function)  | 
            ||
| 339 | |||
| 340 | private static function realTokenIndex(array $tokens, $index)  | 
            ||
| 354 | |||
| 355 | /**  | 
            ||
| 356 | * We need a separate method to check if tokens are operators because we  | 
            ||
| 357 | * occasionally add "..." to short parameter versions. If we simply check  | 
            ||
| 358 | * for `$token[0]` then "..." will incorrectly match the "." operator.  | 
            ||
| 359 | *  | 
            ||
| 360 | * @param array|string $token The token to check  | 
            ||
| 361 | *  | 
            ||
| 362 | * @return bool  | 
            ||
| 363 | */  | 
            ||
| 364 | private static function tokenIsOperator($token)  | 
            ||
| 368 | |||
| 369 | private static function tokensToString(array $tokens)  | 
            ||
| 383 | |||
| 384 | private static function tokensTrim(array $tokens)  | 
            ||
| 406 | |||
| 407 | private static function tokensFormatted(array $tokens)  | 
            ||
| 442 | }  | 
            ||
| 443 | 
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.