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 |
||
14 | class JsonApiExtension extends Extension |
||
15 | { |
||
16 | /** |
||
17 | * Configuration loader |
||
18 | * |
||
19 | * @var LoaderInterface |
||
20 | */ |
||
21 | protected $loader; |
||
22 | |||
23 | /** |
||
24 | * JsonApiExtension constructor. |
||
25 | * |
||
26 | * @param LoaderInterface $loader |
||
27 | */ |
||
28 | 2 | public function __construct(LoaderInterface $loader = null) |
|
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 2 | public function load(array $configs, ContainerBuilder $container) |
|
52 | |||
53 | /** |
||
54 | * Create mappers |
||
55 | * |
||
56 | * @param array $config |
||
57 | * @param ContainerBuilder $container |
||
58 | */ |
||
59 | 2 | protected function createMappers(array $config, ContainerBuilder $container) |
|
82 | |||
83 | /** |
||
84 | * Find mapping handler registered in container |
||
85 | * |
||
86 | * @param ContainerBuilder $container |
||
87 | * @return array |
||
88 | */ |
||
89 | 2 | protected function findMappingHandlers(ContainerBuilder $container): array |
|
90 | { |
||
91 | 2 | $handlers = $container->findTaggedServiceIds('mrtn_json_api.object_mapper.handler'); |
|
92 | |||
93 | 2 | $found = []; |
|
94 | |||
95 | 2 | foreach ($handlers as $id => $tags) |
|
96 | { |
||
97 | 2 | foreach ($tags as $tag) |
|
98 | { |
||
99 | 2 | if (! isset($tag['alias'])) { |
|
100 | continue; |
||
101 | } |
||
102 | |||
103 | 2 | $found[$tag['alias']] = $id; |
|
104 | } |
||
105 | } |
||
106 | |||
107 | 2 | return $found; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * {@inheritdoc} |
||
112 | */ |
||
113 | 1 | public function getAlias() |
|
117 | } |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.