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 |
||
19 | class Flysystem implements IOMetadataHandler |
||
20 | { |
||
21 | /** @var FilesystemInterface */ |
||
22 | private $filesystem; |
||
23 | |||
24 | public function __construct(FilesystemInterface $filesystem) |
||
28 | |||
29 | /** |
||
30 | * Only reads & return metadata, since the binarydata handler took care of creating the file already. |
||
31 | * |
||
32 | * @throws BinaryFileNotFoundException |
||
33 | */ |
||
34 | public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct) |
||
38 | |||
39 | /** |
||
40 | * Does really nothing, the binary data handler takes care of it. |
||
41 | * |
||
42 | * @param $spiBinaryFileId |
||
43 | */ |
||
44 | public function delete($spiBinaryFileId) |
||
47 | |||
48 | public function load($spiBinaryFileId) |
||
58 | |||
59 | public function loadList($scope = null, $limit = null, $offset = null) |
||
73 | |||
74 | public function exists($spiBinaryFileId) |
||
78 | |||
79 | public function getMimeType($spiBinaryFileId) |
||
83 | |||
84 | /** |
||
85 | * Does nothing, as the binarydata handler takes care of it. |
||
86 | */ |
||
87 | public function deleteDirectory($spiPath) |
||
90 | |||
91 | public function count($scope = null) |
||
95 | |||
96 | /** |
||
97 | * Return the metadata of all entries in $scope except directories. |
||
98 | * |
||
99 | * @param string|null $scope The file scope, one of 'binaryfile', 'image', 'mediafile', or null |
||
100 | * @return array |
||
101 | */ |
||
102 | private function getMetadataListWithoutDirectories($scope = null) |
||
118 | |||
119 | /** |
||
120 | * Get the file prefix (storage path) for the given $scope. |
||
121 | * |
||
122 | * @param $scope |
||
123 | * @return string |
||
124 | */ |
||
125 | private function getFilePrefixForScope($scope) |
||
140 | |||
141 | View Code Duplication | private function getSPIBinaryForMetadata($metadata, $spiBinaryFileId = null) |
|
153 | } |
||
154 |