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 |
||
| 14 | class NativeFileInfo implements IFileInfo { |
||
| 15 | /** @var string */ |
||
| 16 | protected $path; |
||
| 17 | /** @var string */ |
||
| 18 | protected $name; |
||
| 19 | /** @var NativeShare */ |
||
| 20 | protected $share; |
||
| 21 | /** @var array{"mode": int, "size": int, "write_time": int}|null */ |
||
| 22 | protected $attributeCache = null; |
||
| 23 | |||
| 24 | public function __construct(NativeShare $share, string $path, string $name) { |
||
| 29 | |||
| 30 | public function getPath(): string { |
||
| 33 | |||
| 34 | public function getName(): string { |
||
| 37 | |||
| 38 | /** |
||
| 39 | 210 | * @return array{"mode": int, "size": int, "write_time": int} |
|
|
|
|||
| 40 | 210 | */ |
|
| 41 | 210 | protected function stat(): array { |
|
| 67 | 190 | ||
| 68 | 190 | public function getSize(): int { |
|
| 72 | 190 | ||
| 73 | public function getMTime(): int { |
||
| 77 | |||
| 78 | /** |
||
| 79 | * On "mode": |
||
| 80 | * |
||
| 81 | * different smbclient versions seem to return different mode values for 'system.dos_attr.mode' |
||
| 82 | 82 | * |
|
| 83 | 82 | * older versions return the dos permissions mask as defined in `IFileInfo::MODE_*` while |
|
| 84 | 62 | * newer versions return the equivalent unix permission mask. |
|
| 85 | * |
||
| 86 | * Since the unix mask doesn't contain the proper hidden/archive/system flags we have to assume them |
||
| 87 | * as false (except for `hidden` where we use the unix dotfile convention) |
||
| 88 | */ |
||
| 89 | |||
| 90 | 2 | protected function getMode(): int { |
|
| 98 | |||
| 99 | View Code Duplication | public function isDirectory(): bool { |
|
| 107 | |||
| 108 | View Code Duplication | public function isReadOnly(): bool { |
|
| 116 | 184 | ||
| 117 | public function isHidden(): bool { |
||
| 125 | |||
| 126 | View Code Duplication | public function isSystem(): bool { |
|
| 134 | 2 | ||
| 135 | 2 | View Code Duplication | public function isArchived(): bool { |
| 143 | |||
| 144 | /** |
||
| 145 | * @return ACL[] |
||
| 146 | 12 | */ |
|
| 147 | 12 | public function getAcls(): array { |
|
| 162 | } |
||
| 163 |
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.