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:
1 | <?php |
||
14 | class Invocations extends PersistentList { |
||
15 | private $parser; |
||
16 | |||
17 | function __construct() { |
||
21 | |||
22 | private function slashit( $path ) { |
||
26 | |||
27 | /** |
||
28 | * Scan every PHP in the root |
||
29 | */ |
||
30 | View Code Duplication | public function scan( $root, $exclude = array() ) { |
|
39 | |||
40 | View Code Duplication | public function scan_dir( $root, $exclude = array() ) { |
|
62 | |||
63 | // public function scan_file( $root, $file_path ) { |
||
64 | // $file_path_relative = str_replace( $root, '', $file_path ); |
||
65 | |||
66 | // $source = file_get_contents( $file_path ); |
||
67 | // try { |
||
68 | // $ast = $this->parser->parse( $source ); |
||
69 | // } catch ( Error $error ) { |
||
70 | // echo "Parse error: {$error->getMessage()}\n"; |
||
71 | // return; |
||
72 | // } |
||
73 | |||
74 | // // $dumper = new NodeDumper; |
||
75 | // // echo $dumper->dump($ast) . "\n"; |
||
76 | |||
77 | // $traverser = new NodeTraverser(); |
||
78 | // $nameResolver = new NameResolver(); |
||
79 | // $traverser->addVisitor( $nameResolver ); |
||
80 | |||
81 | // // Resolve names |
||
82 | // $ast = $traverser->traverse( $ast ); |
||
83 | |||
84 | // // now scan for public methods etc |
||
85 | // $traverser = new NodeTraverser(); |
||
86 | // $declaration_visitor = new Declarations\Visitor( $file_path_relative, $this ); |
||
87 | // $traverser->addVisitor( $declaration_visitor ); |
||
88 | // $ast = $traverser->traverse( $ast ); |
||
89 | // } |
||
90 | |||
91 | /** |
||
92 | * Scans the file for any invocations that depend on missing or different classes, methods, properties and functions |
||
93 | */ |
||
94 | public function scan_file( $root, $file_path, $differences ) { |
||
143 | } |
This check looks for function calls that miss required arguments.