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 |
||
| 21 | class Generator implements Parameterized |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Root of the generation |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | **/ |
||
| 28 | private $root; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The parameters |
||
| 32 | * |
||
| 33 | * @var array[string][string] |
||
| 34 | **/ |
||
| 35 | private $parameters; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The symfony filesystem |
||
| 39 | * |
||
| 40 | * @var Filesystem |
||
| 41 | **/ |
||
| 42 | private $fileSystem; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Constructor |
||
| 46 | * |
||
| 47 | * @param string $root |
||
| 48 | * @param array[string]string $parameters |
||
|
|
|||
| 49 | * @return void |
||
| 50 | **/ |
||
| 51 | public function __construct($root, array $parameters = array()) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Generate a Structure on disk |
||
| 61 | * |
||
| 62 | * @param Structure $directory |
||
| 63 | * @return bool |
||
| 64 | **/ |
||
| 65 | public function generate(Structure $structure) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Get the root directory |
||
| 76 | * |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function getRoot() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Set the root directory |
||
| 86 | * |
||
| 87 | * @param string $root |
||
| 88 | * @return Generator |
||
| 89 | */ |
||
| 90 | public function setRoot($root) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Get the parameters |
||
| 99 | * |
||
| 100 | * @return array[string]string |
||
| 101 | */ |
||
| 102 | public function getParameters() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Set the parameters |
||
| 109 | * |
||
| 110 | * @param array[string]string $parameters |
||
| 111 | * @return Generator |
||
| 112 | */ |
||
| 113 | public function setParameters(array $parameters) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Get the file system |
||
| 122 | * |
||
| 123 | * @return Filesystem |
||
| 124 | */ |
||
| 125 | public function getFilesystem() |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Set the file system |
||
| 132 | * |
||
| 133 | * @param Filesystem $fileSystem |
||
| 134 | * @return Generator |
||
| 135 | */ |
||
| 136 | public function setFilesystem(Filesystem $fileSystem) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Create a node |
||
| 145 | * |
||
| 146 | * @param Node $node |
||
| 147 | * @return bool |
||
| 148 | **/ |
||
| 149 | private function createNode(Node $node) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Create a file |
||
| 172 | * |
||
| 173 | * @param File $file |
||
| 174 | * @return bool |
||
| 175 | **/ |
||
| 176 | View Code Duplication | private function createFile(File $file) |
|
| 202 | |||
| 203 | /** |
||
| 204 | * Create a directory |
||
| 205 | * |
||
| 206 | * @param Directory $directory |
||
| 207 | * @return Generator |
||
| 208 | **/ |
||
| 209 | View Code Duplication | private function createDirectory(Directory $directory) |
|
| 238 | |||
| 239 | /** |
||
| 240 | * Create a symlink |
||
| 241 | * |
||
| 242 | * @param SymLink $link |
||
| 243 | * @return Generator |
||
| 244 | **/ |
||
| 245 | private function createLink(SymLink $link) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get the full path to a node, including the root path |
||
| 279 | * |
||
| 280 | * @see getRoot() |
||
| 281 | * |
||
| 282 | * @param Node $node |
||
| 283 | * @return string |
||
| 284 | **/ |
||
| 285 | private function getNodePath(Node $node) |
||
| 291 | } |
||
| 292 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.