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 |
||
| 11 | abstract class FlysystemStorageAdapter implements LoggerAwareInterface, StorageAdapterInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var Filesystem |
||
| 15 | */ |
||
| 16 | protected $filesystem; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var LoggerInterface |
||
| 20 | */ |
||
| 21 | protected $logger; |
||
| 22 | |||
| 23 | public function __construct(Filesystem $filesystem) |
||
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritdoc} |
||
| 31 | */ |
||
| 32 | public function setLogger(LoggerInterface $logger): void |
||
| 36 | |||
| 37 | View Code Duplication | public function writeStream(string $relativePath, $stream) |
|
| 55 | |||
| 56 | public function exists(string $relativePath): bool |
||
| 67 | |||
| 68 | View Code Duplication | public function unlink(string $relativePath) |
|
| 86 | |||
| 87 | View Code Duplication | public function getReadStream(string $relativePath) |
|
| 107 | } |
||
| 108 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.