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 |
||
11 | class Di |
||
|
|||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $providerDir; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | private $providerClass; |
||
23 | |||
24 | /** |
||
25 | * @var Scanner[] |
||
26 | */ |
||
27 | private $scanners; |
||
28 | |||
29 | /** |
||
30 | * @var Reader |
||
31 | */ |
||
32 | private $reader; |
||
33 | |||
34 | /** |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $debug; |
||
38 | |||
39 | private static $template = '<?php |
||
40 | |||
41 | /** |
||
42 | * {{ provider_class }} |
||
43 | * |
||
44 | * This class has been auto-generated by Eccube\Di\ProviderGenerator |
||
45 | */ |
||
46 | class {{ provider_class }} implements \Pimple\ServiceProviderInterface |
||
47 | { |
||
48 | public function register(\Pimple\Container $app) |
||
49 | { |
||
50 | {{ snippets|raw }} |
||
51 | } |
||
52 | }'; |
||
53 | |||
54 | /** |
||
55 | * Di constructor. |
||
56 | * @param string $providerDir |
||
57 | * @param string $providerClass |
||
58 | * @param Scanner[] $scanners |
||
59 | * @param Reader $reader |
||
60 | * @param bool $debug |
||
61 | */ |
||
62 | 1142 | public function __construct($providerDir, $providerClass, array $scanners, Reader $reader, $debug) |
|
70 | |||
71 | |||
72 | 18 | public function isApplication($class) |
|
76 | |||
77 | 1142 | public function getProviderPath() |
|
81 | |||
82 | 1140 | public function build(Container $container) |
|
95 | |||
96 | 23 | public function findClasses(array $dirs) |
|
123 | |||
124 | 22 | private function generateServiceProvider() |
|
179 | } |
||
180 |