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 | final class FbpDumper implements FbpDefinitionsInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | private static $processes; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param array $definition |
||
| 32 | * @return string json |
||
| 33 | */ |
||
| 34 | 1 | public static function toJson(array $definition) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @param array $definition |
||
| 41 | * @param int $inline level until inlining starts |
||
| 42 | * @return string yaml |
||
| 43 | */ |
||
| 44 | 1 | public static function toYaml(array $definition, $inline = 3) |
|
| 48 | |||
| 49 | /** |
||
| 50 | * @param array $definition |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | 1 | public static function toFbp(array $definition) |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @param array $definition |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | 1 | private static function createFbp(array $definition) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Look for all needed fields and build a port -> port connection. |
||
| 103 | * |
||
| 104 | * @param array $connectionTouple |
||
| 105 | * @return string |
||
| 106 | */ |
||
| 107 | 2 | private static function examineConnectionTouple(array $connectionTouple) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * @param string $type |
||
| 120 | * @param array $processPart |
||
| 121 | * @return string |
||
| 122 | */ |
||
| 123 | 1 | private static function examineProcess($type, array $processPart) |
|
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $needle |
||
| 150 | * @param array $haystack |
||
| 151 | * @param bool $triggerException |
||
| 152 | * @return bool |
||
| 153 | */ |
||
| 154 | 1 | private static function hasElement($needle, array $haystack, $triggerException = true) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * @param string $sourcePort |
||
| 169 | * @param string $targetPort |
||
| 170 | * @return string |
||
| 171 | */ |
||
| 172 | 1 | private static function connectPorts($sourcePort, $targetPort) |
|
| 182 | } |
||
| 183 |