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 | class Ftp extends Remote implements Collector |
||
24 | { |
||
25 | /** |
||
26 | * FTP connection stream |
||
27 | * |
||
28 | * @var \SebastianFeldmann\Ftp\Client |
||
29 | */ |
||
30 | private $ftpClient; |
||
31 | |||
32 | /** |
||
33 | * Ftp constructor. |
||
34 | * |
||
35 | * @param \phpbu\App\Backup\Target $target |
||
36 | * @param \phpbu\App\Backup\Path $remotePath |
||
37 | * @param \SebastianFeldmann\Ftp\Client $ftpClient |
||
38 | */ |
||
39 | public function __construct(Target $target, Path $remotePath, Client $ftpClient) |
||
44 | |||
45 | /** |
||
46 | * Collect all created backups. |
||
47 | * |
||
48 | * @throws \Exception |
||
49 | */ |
||
50 | protected function collectBackups() |
||
59 | |||
60 | /** |
||
61 | * Collect all synced backup files regarding to the remote path configuration. |
||
62 | * |
||
63 | * @param string $remotePath |
||
64 | * @param int $depth |
||
65 | * @throws \Exception |
||
66 | */ |
||
67 | private function collect(string $remotePath, int $depth) |
||
75 | |||
76 | /** |
||
77 | * If path not fully satisfied look for matching directories. |
||
78 | * |
||
79 | * @param string $remotePath |
||
80 | * @param int $depth |
||
81 | * @return void |
||
82 | * @throws \Exception |
||
83 | */ |
||
84 | private function collectDirectories(string $remotePath, int $depth) |
||
96 | |||
97 | /** |
||
98 | * Collect all matching files in a given remote directory. |
||
99 | * |
||
100 | * @param string $remotePath |
||
101 | * @return void |
||
102 | * @throws \Exception |
||
103 | */ |
||
104 | private function collectFiles(string $remotePath) |
||
114 | } |
||
115 |