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 | View Code Duplication | final class EnvFilesLocator implements FixtureLocatorInterface |
|
|
|
|||
| 23 | { |
||
| 24 | use NotClonableTrait; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $fixturesPath; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $fixturePath Path to which to look for fixtures relative to the bundle path. |
||
| 33 | */ |
||
| 34 | public function __construct(string $fixturePath) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Locate fixture files found matching the environment name. |
||
| 41 | * |
||
| 42 | * For example, if the given fixture path is 'Resources/fixtures', it will try to locate |
||
| 43 | * the files in the 'Resources/fixtures/*.dev.yml' for each bundle passed ('dev' being the |
||
| 44 | * environment). |
||
| 45 | * |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | public function locateFiles(array $bundles, string $environment): array |
||
| 57 | |||
| 58 | private function locateBundleFiles(BundleInterface $bundle, string $environment): array |
||
| 74 | } |
||
| 75 |
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.