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 |
||
13 | class Shell { |
||
14 | use Module; |
||
15 | |||
16 | protected static $aliases = []; |
||
17 | protected $command; |
||
18 | |||
19 | /** |
||
20 | * Compile a shell command |
||
21 | * @param string $command |
||
22 | * @param array $params |
||
23 | * @return string |
||
24 | */ |
||
25 | protected static function _compileCommand($command,array $params){ |
||
48 | |||
49 | /** |
||
50 | * Returns the compiled shell command |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getShellCommand(){ |
||
56 | |||
57 | public static function __callStatic($command,$params){ |
||
68 | |||
69 | public function __construct($command,$params=null){ |
||
72 | |||
73 | public function __toString(){ |
||
78 | |||
79 | /** |
||
80 | * Concatenate multiple shell commands via piping |
||
81 | * @return Shell The piped shell command |
||
82 | */ |
||
83 | View Code Duplication | public static function pipe(/* ... */){ |
|
90 | |||
91 | /** |
||
92 | * Concatenate multiple shell commands via logical implication ( && ) |
||
93 | * @return Shell The concatenated shell command |
||
94 | */ |
||
95 | View Code Duplication | public static function sequence(...$items){ |
|
102 | |||
103 | public static function execCommand($command,$params = null){ |
||
106 | |||
107 | public static function alias($command,callable $callback){ |
||
110 | |||
111 | public static function escape($arg){ |
||
114 | |||
115 | public function run(){ |
||
118 | |||
119 | } /* End of class */ |
||
120 | |||
121 |