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 |
||
| 22 | class CachingLoader extends CachingLoaderDecorator |
||
| 23 | { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var CollectionInterface $cache |
||
| 27 | */ |
||
| 28 | protected $cache; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string $identifier |
||
| 32 | */ |
||
| 33 | protected $identifier; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var ClassInterfaceCache $class_cache |
||
| 37 | */ |
||
| 38 | private $class_cache; |
||
| 39 | |||
| 40 | |||
| 41 | /** |
||
| 42 | * CachingLoader constructor. |
||
| 43 | * |
||
| 44 | * @param LoaderDecoratorInterface $loader |
||
| 45 | * @param CollectionInterface $cache |
||
| 46 | * @param ClassInterfaceCache $class_cache |
||
| 47 | * @param string $identifier |
||
| 48 | * @throws InvalidDataTypeException |
||
| 49 | */ |
||
| 50 | public function __construct( |
||
| 76 | |||
| 77 | |||
| 78 | /** |
||
| 79 | * @return string |
||
| 80 | */ |
||
| 81 | public function identifier() |
||
| 85 | |||
| 86 | |||
| 87 | /** |
||
| 88 | * @param string $identifier |
||
| 89 | * @throws InvalidDataTypeException |
||
| 90 | */ |
||
| 91 | private function setIdentifier($identifier) |
||
| 98 | |||
| 99 | |||
| 100 | /** |
||
| 101 | * @param FullyQualifiedName|string $fqcn |
||
| 102 | * @param mixed $object |
||
| 103 | * @return bool |
||
| 104 | * @throws InvalidArgumentException |
||
| 105 | */ |
||
| 106 | public function share($fqcn, $object) |
||
| 121 | |||
| 122 | |||
| 123 | /** |
||
| 124 | * @param FullyQualifiedName|string $fqcn |
||
| 125 | * @param array $arguments |
||
| 126 | * @param bool $shared |
||
| 127 | * @param array $interfaces |
||
| 128 | * @return mixed |
||
| 129 | */ |
||
| 130 | public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
||
| 156 | |||
| 157 | |||
| 158 | /** |
||
| 159 | * empties cache and calls reset() on loader if method exists |
||
| 160 | */ |
||
| 161 | public function reset() |
||
| 166 | |||
| 167 | |||
| 168 | /** |
||
| 169 | * build a string representation of a class' name and arguments |
||
| 170 | * |
||
| 171 | * @param string $fqcn |
||
| 172 | * @param array $arguments |
||
| 173 | * @return string |
||
| 174 | */ |
||
| 175 | private function getClassIdentifier($fqcn, array $arguments = array()) |
||
| 187 | |||
| 188 | |||
| 189 | /** |
||
| 190 | * build a string representation of a class' arguments |
||
| 191 | * (mostly because Closures can't be serialized) |
||
| 192 | * |
||
| 193 | * @param array $arguments |
||
| 194 | * @return string |
||
| 195 | */ |
||
| 196 | protected function getIdentifierForArguments(array $arguments) |
||
| 218 | } |
||
| 219 | // End of file CachingLoader.php |
||
| 221 |