Conditions | 34 |
Paths | 6344 |
Total Lines | 112 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
119 | public function main() |
||
120 | { |
||
121 | if ( |
||
122 | null === $this->file |
||
123 | && null === $this->dir |
||
124 | && 0 === count($this->dirsets) |
||
125 | && 0 === count($this->filesets) |
||
126 | && 0 === count($this->filelists) |
||
127 | ) { |
||
128 | throw new BuildException( |
||
129 | 'At least one of the file or dir attributes, or a fileset, filelist or dirset element must be set.' |
||
130 | ); |
||
131 | } |
||
132 | |||
133 | if ($this->quiet && $this->failonerror) { |
||
134 | throw new BuildException('quiet and failonerror cannot both be set to true', $this->getLocation()); |
||
135 | } |
||
136 | |||
137 | // delete a single file |
||
138 | if (null !== $this->file) { |
||
139 | if ($this->file->exists()) { |
||
140 | if ($this->file->isDirectory()) { |
||
141 | $this->log( |
||
142 | 'Directory ' . $this->file->__toString() . ' cannot be removed using the file attribute. Use dir instead.' |
||
143 | ); |
||
144 | } else { |
||
145 | $this->log('Deleting: ' . $this->file->__toString()); |
||
146 | |||
147 | try { |
||
148 | $this->file->delete(); |
||
149 | } catch (Exception $e) { |
||
150 | $message = 'Unable to delete file ' . $this->file->__toString() . ': ' . $e->getMessage(); |
||
151 | if ($this->failonerror) { |
||
152 | throw new BuildException($message); |
||
153 | } |
||
154 | |||
155 | $this->log($message, $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN); |
||
156 | } |
||
157 | } |
||
158 | } else { |
||
159 | $message = 'Could not find file ' . $this->file->getAbsolutePath() . ' to delete.'; |
||
160 | |||
161 | if ($this->failonerror) { |
||
162 | throw new BuildException($message); |
||
163 | } |
||
164 | |||
165 | $this->log($message, ($this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN)); |
||
166 | } |
||
167 | } |
||
168 | |||
169 | if (null !== $this->dir) { |
||
170 | $this->dirsets[] = $this->dir; |
||
171 | } |
||
172 | foreach ($this->dirsets as $dirset) { |
||
173 | if (!$dirset instanceof File) { |
||
174 | $ds = $dirset->getDirectoryScanner($this->getProject()); |
||
175 | $dirs = $ds->getIncludedDirectories(); |
||
176 | $baseDir = $ds->getBasedir(); |
||
177 | } else { |
||
178 | $dirs[0] = $dirset; |
||
179 | } |
||
180 | foreach ($dirs as $dir) { |
||
181 | if (!$dir instanceof File) { |
||
182 | $dir = new File($baseDir, $dir); |
||
|
|||
183 | } |
||
184 | if ($dir->exists() && $dir->isDirectory()) { |
||
185 | if (Project::MSG_VERBOSE === $this->verbosity) { |
||
186 | $this->log('Deleting directory ' . $dir->__toString()); |
||
187 | } |
||
188 | $this->removeDir($dir); |
||
189 | } else { |
||
190 | $message = 'Directory ' . $dir->getAbsolutePath() . ' does not exist or is not a directory.'; |
||
191 | |||
192 | if ($this->failonerror) { |
||
193 | throw new BuildException($message); |
||
194 | } |
||
195 | |||
196 | $this->log($message, ($this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN)); |
||
197 | } |
||
198 | } |
||
199 | } |
||
200 | |||
201 | // delete the files in the filelists |
||
202 | foreach ($this->filelists as $fl) { |
||
203 | try { |
||
204 | $files = $fl->getFiles($this->project); |
||
205 | $empty = []; |
||
206 | $this->removeFiles($fl->getDir($this->project), $files, $empty); |
||
207 | } catch (BuildException $be) { |
||
208 | // directory doesn't exist or is not readable |
||
209 | if ($this->failonerror) { |
||
210 | throw $be; |
||
211 | } |
||
212 | |||
213 | $this->log($be->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN); |
||
214 | } |
||
215 | } |
||
216 | |||
217 | // delete the files in the filesets |
||
218 | foreach ($this->filesets as $fs) { |
||
219 | try { |
||
220 | $ds = $fs->getDirectoryScanner($this->project); |
||
221 | $files = $ds->getIncludedFiles(); |
||
222 | $dirs = $ds->getIncludedDirectories(); |
||
223 | $this->removeFiles($fs->getDir($this->project), $files, $dirs); |
||
224 | } catch (BuildException $be) { |
||
225 | // directory doesn't exist or is not readable |
||
226 | if ($this->failonerror) { |
||
227 | throw $be; |
||
228 | } |
||
229 | |||
230 | $this->log($be->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN); |
||
231 | } |
||
339 |