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 |
||
19 | abstract class Proxy implements ProxyInterface { |
||
1 ignored issue
–
show
|
|||
20 | use EntityManagerConsumerTrait; |
||
21 | /** |
||
22 | * The sports db client. |
||
23 | * |
||
24 | * @var TheSportsDb\Http\TheSportsDbClientInterface |
||
25 | */ |
||
26 | protected $sportsDbClient; |
||
27 | |||
28 | /** |
||
29 | * The already available properties. |
||
30 | * |
||
31 | * @var \stdClass |
||
32 | */ |
||
33 | protected $properties; |
||
34 | |||
35 | /** |
||
36 | * The fully loaded entity object (lazy-loaded when needed). |
||
37 | * |
||
38 | * @var mixed |
||
39 | */ |
||
40 | protected $entity; |
||
41 | |||
42 | /** |
||
43 | * Creates a new Proxy object. |
||
44 | * |
||
45 | * @param \stdClass $values |
||
46 | * The sport data. |
||
47 | * @param \TheSportsDb\Http\TheSportsDbClientInterface $sportsDbClient |
||
48 | * A sports db client |
||
49 | * @param \TheSportsDb\Entity\Factory\FactoryInterface $factory |
||
50 | * The sport factory. |
||
51 | */ |
||
52 | public function __construct(\stdClass $values) { |
||
56 | |||
57 | public function update(\stdClass $values) { |
||
67 | |||
68 | public function setEntityManager(EntityManagerInterface $entityManager) { |
||
74 | |||
75 | public function setSportsDbClient(TheSportsDbClientInterface $sportsDbClient) { |
||
78 | |||
79 | /** |
||
80 | * Gets a property, if it exists, loads it if necessary. |
||
81 | * |
||
82 | * @param string $name |
||
83 | * The property name. |
||
84 | * |
||
85 | * @return mixed |
||
86 | * The property value. |
||
87 | */ |
||
88 | protected function get($name) { |
||
105 | |||
106 | /** |
||
107 | * Lazy loads an entity. |
||
108 | * |
||
109 | * @throws \Exception |
||
110 | * When the entity is not found. |
||
111 | */ |
||
112 | abstract protected function load(); |
||
113 | |||
114 | public function raw() { |
||
146 | |||
147 | public static function getEntityType() { |
||
151 | |||
152 | public static function getPropertyMapDefinition() { |
||
156 | } |
||
157 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.