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 |
||
| 20 | final class SpomkyLabsJoseBundleExtension extends Extension |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var \SpomkyLabs\JoseBundle\DependencyInjection\JWKSource\JWKSourceInterface[] |
||
| 24 | */ |
||
| 25 | private $jwk_sources; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var \SpomkyLabs\JoseBundle\DependencyInjection\JWKSetSource\JWKSetSourceInterface[] |
||
| 29 | */ |
||
| 30 | private $jwk_set_sources; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | private $alias; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param string $alias |
||
| 39 | */ |
||
| 40 | public function __construct($alias) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | public function load(array $configs, ContainerBuilder $container) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * {@inheritdoc} |
||
| 68 | */ |
||
| 69 | public function getConfiguration(array $configs, ContainerBuilder $container) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | public function getAlias() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
||
| 87 | * @param array $config |
||
| 88 | */ |
||
| 89 | private function initConfiguration(ContainerBuilder $container, array $config) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param string $name |
||
| 110 | * @param array $config |
||
| 111 | * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
||
| 112 | * @param \SpomkyLabs\JoseBundle\DependencyInjection\JWKSetSource\JWKSetSourceInterface[] $jwk_set_sources |
||
| 113 | */ |
||
| 114 | View Code Duplication | private function createJWKSet($name, array $config, ContainerBuilder $container, array $jwk_set_sources) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * @param string $name |
||
| 129 | * @param array $config |
||
| 130 | * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container |
||
| 131 | * @param \SpomkyLabs\JoseBundle\DependencyInjection\JWKSource\JWKSourceInterface[] $jwk_sources |
||
| 132 | */ |
||
| 133 | View Code Duplication | private function createJWK($name, array $config, ContainerBuilder $container, array $jwk_sources) |
|
| 145 | |||
| 146 | /** |
||
| 147 | * @return string[] |
||
| 148 | */ |
||
| 149 | private function getXmlFileToLoad() |
||
| 159 | |||
| 160 | View Code Duplication | private function createJWKSources() |
|
| 180 | |||
| 181 | View Code Duplication | private function createJWKSetSources() |
|
| 201 | } |
||
| 202 |
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.