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 NetgenOpenGraphRuntime |
||
12 | { |
||
13 | /** |
||
14 | * @var \Netgen\Bundle\OpenGraphBundle\MetaTag\CollectorInterface |
||
15 | */ |
||
16 | protected $tagCollector; |
||
17 | |||
18 | /** |
||
19 | * @var \Netgen\Bundle\OpenGraphBundle\MetaTag\RendererInterface |
||
20 | */ |
||
21 | protected $tagRenderer; |
||
22 | |||
23 | /** |
||
24 | * @var \Psr\Log\LoggerInterface |
||
25 | */ |
||
26 | protected $logger; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | protected $throwExceptions = true; |
||
32 | |||
33 | /** |
||
34 | * Constructor. |
||
35 | * |
||
36 | * @param \Netgen\Bundle\OpenGraphBundle\MetaTag\CollectorInterface $tagCollector |
||
37 | * @param \Netgen\Bundle\OpenGraphBundle\MetaTag\RendererInterface $tagRenderer |
||
38 | * @param \Psr\Log\LoggerInterface $logger |
||
39 | */ |
||
40 | public function __construct( |
||
49 | |||
50 | /** |
||
51 | * Sets the flag that determines if the exceptions will thrown instead of logged. |
||
52 | * |
||
53 | * @param bool $throwExceptions |
||
54 | */ |
||
55 | public function setThrowExceptions($throwExceptions = true) |
||
59 | |||
60 | /** |
||
61 | * Renders Open Graph tags for provided content. |
||
62 | * |
||
63 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | View Code Duplication | public function renderOpenGraphTags(Content $content) |
|
83 | |||
84 | /** |
||
85 | * Returns Open Graph tags for provided content. |
||
86 | * |
||
87 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
88 | * |
||
89 | * @return \Netgen\Bundle\OpenGraphBundle\MetaTag\Item[] |
||
90 | */ |
||
91 | View Code Duplication | public function getOpenGraphTags(Content $content) |
|
105 | } |
||
106 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.