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 |
||
28 | class AppManager { |
||
29 | |||
30 | /** |
||
31 | * @var OccRunner $occRunner |
||
32 | */ |
||
33 | protected $occRunner; |
||
34 | |||
35 | /** |
||
36 | * @var array $disabledApps |
||
37 | */ |
||
38 | protected $disabledApps = []; |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * @param OccRunner $occRunner |
||
43 | */ |
||
44 | 5 | public function __construct(OccRunner $occRunner){ |
|
47 | |||
48 | 1 | public function disableApp($appId){ |
|
49 | try{ |
||
50 | 1 | $this->occRunner->run('app:disable ' . ProcessUtils::escapeArgument($appId)); |
|
51 | } catch (\Exception $e){ |
||
52 | return false; |
||
53 | } |
||
54 | 1 | return true; |
|
55 | } |
||
56 | |||
57 | 1 | public function enableApp($appId){ |
|
58 | try{ |
||
59 | 1 | $this->occRunner->run('app:enable ' . ProcessUtils::escapeArgument($appId)); |
|
60 | 1 | array_unshift($this->disabledApps, $appId); |
|
61 | } catch (\Exception $e){ |
||
62 | return false; |
||
63 | } |
||
64 | 1 | return true; |
|
65 | } |
||
66 | |||
67 | public function disableNotShippedApps(OutputInterface $output = null){ |
||
79 | |||
80 | public function reenableNotShippedApps(OutputInterface $output = null){ |
||
90 | |||
91 | public function getAllApps(){ |
||
96 | |||
97 | 2 | public function getShippedApps(){ |
|
102 | |||
103 | 1 | public function getAppPath($appId){ |
|
104 | try { |
||
111 | |||
112 | } |
||
113 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.