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 ConsoleContainerBuilder extends ContainerBuilder |
||
23 | { |
||
24 | static $DEFAULT_ANNOTATIONS=[ |
||
|
|||
25 | [ClassAnnotationHandler::class, 'class'], |
||
26 | [CommandNameAnnotationHandler::class, "class.children[?name=='command']"], |
||
27 | [CommandAnnotationHandler::class, "methods.*.children[?name=='command'][]"], |
||
28 | [ParamAnnotationHandler::class, "methods.*.children[?name=='param'][]"], |
||
29 | [ValidateAnnotationHandler::class, "methods.*.children[].children[?name=='v'][]"], |
||
30 | ]; |
||
31 | /** |
||
32 | * @var FactoryInterface |
||
33 | */ |
||
34 | private $factory; |
||
35 | /** |
||
36 | * @var DIInvokerInterface |
||
37 | */ |
||
38 | private $diInvoker; |
||
39 | |||
40 | 1 | View Code Duplication | public function __construct(FactoryInterface $factory, |
54 | |||
55 | /** |
||
56 | * @param string $className |
||
57 | * @return ConsoleContainer |
||
58 | */ |
||
59 | 1 | protected function createContainer($className) |
|
63 | |||
64 | 1 | protected function handleAnnotation($handlerName, $container, $ann) |
|
69 | |||
70 | 1 | protected function postCreateContainer($object) |
|
76 | } |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.