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 DependencyBuilder |
||
|
|
|||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $providerDir; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $providerClass; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var AutoWiring[] |
||
| 26 | */ |
||
| 27 | private $wirings; |
||
| 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\DependencyBuilder |
||
| 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 AutoWiring[] $wirings |
||
| 59 | * @param Reader $reader |
||
| 60 | * @param bool $debug |
||
| 61 | */ |
||
| 62 | 1124 | public function __construct($providerDir, $providerClass, array $wirings, Reader $reader, $debug) |
|
| 70 | |||
| 71 | |||
| 72 | 18 | public function isApplication($class) |
|
| 76 | |||
| 77 | 1124 | public function getProviderPath() |
|
| 81 | |||
| 82 | 1122 | public function build(Container $container) |
|
| 95 | |||
| 96 | 27 | public function findClasses(array $dirs) |
|
| 123 | |||
| 124 | 26 | private function generateServiceProvider() |
|
| 179 | } |
||
| 180 |