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 |
||
| 23 | class TranslatableFieldsCompilerPass implements CompilerPassInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var DocumentMap |
||
| 27 | */ |
||
| 28 | private $documentMap; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Make translatable fields map and set it to parameter |
||
| 32 | * |
||
| 33 | * @param ContainerBuilder $container container builder |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | 4 | View Code Duplication | public function process(ContainerBuilder $container) |
| 37 | { |
||
| 38 | 4 | $this->documentMap = $container->get('graviton.document.map'); |
|
| 39 | |||
| 40 | 4 | $map = []; |
|
| 41 | 4 | foreach ($this->documentMap->getDocuments() as $document) { |
|
| 42 | 4 | $map[$document->getClass()] = $this->getTranslatableFields($document); |
|
| 43 | 2 | } |
|
| 44 | 4 | $container->setParameter('graviton.document.type.translatable.fields', $map); |
|
| 45 | 4 | } |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Get document fields |
||
| 49 | * |
||
| 50 | * @param Document $document Document |
||
| 51 | * @param string $prefix Field prefix |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | 4 | private function getTranslatableFields(Document $document, $prefix = '') |
|
| 91 | } |
||
| 92 |