| Conditions | 10 |
| Paths | 6 |
| Total Lines | 25 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 10 |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 36 | 14 | public function __invoke($replace = false) |
|
| 37 | { |
||
| 38 | 14 | if (!$this->originResourceDO->getName() || !$this->originResourceDO->getType()) { |
|
| 39 | 1 | throw new CommandErrorException('Source resource cannot be empty'); |
|
| 40 | } |
||
| 41 | 13 | if (!$this->newResourceDO->getName() || !$this->newResourceDO->getType()) { |
|
| 42 | 1 | throw new CommandErrorException('Destination resource cannot be empty'); |
|
| 43 | } |
||
| 44 | 12 | $originPath = $this->originResourceDO->getFilePath(); |
|
| 45 | 12 | $newPath = $this->newResourceDO->getFilePath(); |
|
|
1 ignored issue
–
show
|
|||
| 46 | 12 | if ($originPath === $newPath) { |
|
| 47 | 1 | throw new CommandErrorException('Source and destination paths is equal'); |
|
| 48 | } |
||
| 49 | 11 | if (!$this->filesystem->has($originPath)) { |
|
| 50 | 1 | throw new CommandErrorException('Origin file is not exists: ' . $originPath); |
|
| 51 | } |
||
| 52 | 10 | $exists = $this->filesystem->has($newPath); |
|
| 53 | 10 | if (!$exists || $replace) { |
|
| 54 | 9 | $this->copyFile($originPath, $newPath, $exists && $replace); |
|
| 55 | |||
| 56 | 9 | return $this->newResourceDO; |
|
| 57 | } |
||
| 58 | |||
| 59 | 1 | return $this->originResourceDO; |
|
| 60 | } |
||
| 61 | |||
| 79 | } |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.