Total Complexity | 63 |
Total Lines | 391 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like FtpDeployTask often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FtpDeployTask, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
56 | class FtpDeployTask extends Task |
||
57 | { |
||
58 | use FileSetAware; |
||
59 | use LogLevelAware; |
||
60 | |||
61 | private $host = null; |
||
62 | private $port = 21; |
||
63 | private $ssl = false; |
||
64 | private $username; |
||
65 | private $password; |
||
66 | private $dir; |
||
67 | private $mode = FTP_BINARY; |
||
68 | private $clearFirst = false; |
||
69 | private $passive = false; |
||
70 | private $depends = false; |
||
71 | private $dirmode = false; |
||
72 | private $filemode = false; |
||
73 | private $rawDataFallback = false; |
||
74 | private $skipOnSameSize = false; |
||
75 | |||
76 | public function __construct() |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param string $host |
||
84 | */ |
||
85 | public function setHost(string $host): void |
||
86 | { |
||
87 | $this->host = $host; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param int $port |
||
92 | */ |
||
93 | public function setPort(int $port): void |
||
94 | { |
||
95 | $this->port = $port; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param bool $ssl |
||
100 | */ |
||
101 | public function setSsl(bool $ssl): void |
||
102 | { |
||
103 | $this->ssl = $ssl; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @param string $username |
||
108 | */ |
||
109 | public function setUsername($username): void |
||
110 | { |
||
111 | $this->username = $username; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @param string $password |
||
116 | */ |
||
117 | public function setPassword(string $password) |
||
118 | { |
||
119 | $this->password = $password; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param $dir |
||
124 | */ |
||
125 | public function setDir($dir) |
||
126 | { |
||
127 | $this->dir = $dir; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @param $mode |
||
132 | */ |
||
133 | public function setMode($mode) |
||
134 | { |
||
135 | switch (strtolower($mode)) { |
||
136 | case 'ascii': |
||
137 | $this->mode = FTP_ASCII; |
||
138 | break; |
||
139 | case 'binary': |
||
140 | case 'bin': |
||
141 | $this->mode = FTP_BINARY; |
||
142 | break; |
||
143 | } |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @param bool $passive |
||
148 | */ |
||
149 | public function setPassive(bool $passive): void |
||
150 | { |
||
151 | $this->passive = $passive; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * @param bool $clearFirst |
||
156 | */ |
||
157 | public function setClearFirst(bool $clearFirst): void |
||
158 | { |
||
159 | $this->clearFirst = $clearFirst; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @param bool $depends |
||
164 | */ |
||
165 | public function setDepends(bool $depends): void |
||
166 | { |
||
167 | $this->depends = $depends; |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @param string $filemode |
||
172 | */ |
||
173 | public function setFilemode($filemode): void |
||
174 | { |
||
175 | $this->filemode = octdec(str_pad($filemode, 4, '0', STR_PAD_LEFT)); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * @param $dirmode |
||
180 | */ |
||
181 | public function setDirmode($dirmode): void |
||
182 | { |
||
183 | $this->dirmode = octdec(str_pad($dirmode, 4, '0', STR_PAD_LEFT)); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * @param $fallback |
||
188 | */ |
||
189 | public function setRawdatafallback(bool $fallback): void |
||
190 | { |
||
191 | $this->rawDataFallback = $fallback; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @param bool|string|int $skipOnSameSize |
||
196 | */ |
||
197 | public function setSkipOnSameSize($skipOnSameSize): void |
||
198 | { |
||
199 | $this->skipOnSameSize = StringHelper::booleanValue($skipOnSameSize); |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * The init method: check if Net_FTP is available |
||
204 | */ |
||
205 | public function init() |
||
206 | { |
||
207 | $paths = Phing::explodeIncludePath(); |
||
208 | foreach ($paths as $path) { |
||
209 | if (file_exists($path . DIRECTORY_SEPARATOR . 'Net' . DIRECTORY_SEPARATOR . 'FTP.php')) { |
||
210 | return true; |
||
211 | } |
||
212 | } |
||
213 | throw new BuildException('The FTP Deploy task requires the Net_FTP PEAR package.'); |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * The main entry point method. |
||
218 | */ |
||
219 | public function main() |
||
358 | } |
||
359 | |||
360 | /** |
||
361 | * @param \Net_FTP $ftp |
||
362 | * @param $remoteFileInformations |
||
363 | * @param $directory |
||
364 | * @return bool |
||
365 | */ |
||
366 | private function directoryInformations(\Net_FTP $ftp, &$remoteFileInformations, $directory) |
||
367 | { |
||
368 | $content = $ftp->ls($directory); |
||
369 | if (@\PEAR::isError($content)) { |
||
370 | if ($this->rawDataFallback) { |
||
371 | $content = $ftp->ls($directory, NET_FTP_RAWLIST); |
||
372 | } |
||
373 | if (@\PEAR::isError($content)) { |
||
374 | return false; |
||
375 | } |
||
376 | $content = $this->parseRawFtpContent($content, $directory); |
||
377 | } |
||
378 | |||
379 | if (count($content) == 0) { |
||
380 | return false; |
||
381 | } |
||
382 | |||
383 | if (!empty($directory)) { |
||
384 | $directory .= '/'; |
||
385 | } |
||
386 | foreach ($content as $val) { |
||
387 | if ($val['name'] !== '.' && $val['name'] !== '..') { |
||
388 | $remoteFileInformations[$directory . $val['name']] = $val; |
||
389 | } |
||
390 | } |
||
391 | |||
392 | return true; |
||
393 | } |
||
394 | |||
395 | /** |
||
396 | * @param $content |
||
397 | * @param null $directory |
||
398 | * @return array |
||
399 | */ |
||
400 | private function parseRawFtpContent($content, $directory = null): array |
||
447 | } |
||
448 | } |
||
449 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths