| Conditions | 10 |
| Paths | 5 |
| Total Lines | 34 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 10 |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 39 | 7 | public function __invoke() |
|
| 40 | { |
||
| 41 | 7 | $originName = $this->originResourceDO->getName(); |
|
|
1 ignored issue
–
show
|
|||
| 42 | 7 | $suspectName = $this->suspectResourceDO->getName(); |
|
|
1 ignored issue
–
show
|
|||
| 43 | 7 | $originType = $this->originResourceDO->getType(); |
|
|
1 ignored issue
–
show
|
|||
| 44 | 7 | $suspectType = $this->suspectResourceDO->getType(); |
|
|
1 ignored issue
–
show
|
|||
| 45 | 7 | $originFilePath = $this->originResourceDO->getFilePath(); |
|
|
1 ignored issue
–
show
|
|||
| 46 | 7 | $suspectFilePath = $this->suspectResourceDO->getFilePath(); |
|
| 47 | |||
| 48 | 7 | if (!$originName || !$originType) { |
|
| 49 | 1 | throw new CommandErrorException('Cannot destroy equal resource: the origin resource is empty'); |
|
| 50 | } |
||
| 51 | 6 | if (!$suspectName || !$suspectType) { |
|
| 52 | 1 | throw new CommandErrorException('Cannot destroy equal resource: the suspect resource is empty'); |
|
| 53 | } |
||
| 54 | 5 | if ($originFilePath === $suspectFilePath) { |
|
| 55 | 1 | throw new CommandErrorException('Cannot destroy equal resource: Origin and Suspect have same paths'); |
|
| 56 | } |
||
| 57 | |||
| 58 | // Unfortunately, this condition can not always work fine. |
||
| 59 | // Because some Middlewares can compress, resize etc. the resource that saved before |
||
| 60 | // and the second uploaded copy will never be equal |
||
| 61 | if ($originType === $suspectType |
||
| 62 | 4 | && $this->filesystem->has($originFilePath) === $this->filesystem->has($suspectFilePath) |
|
| 63 | 4 | && $this->filesystem->getSize($originFilePath) === $this->filesystem->getSize($suspectFilePath) |
|
| 64 | 4 | && $this->getFileHash($originFilePath) === $this->getFileHash($suspectFilePath) |
|
| 65 | 4 | ) { |
|
| 66 | 2 | $command = new DestroyResourceCommand($this->suspectResourceDO, $this->filesystem); |
|
| 67 | |||
| 68 | 2 | return $command(true); |
|
| 69 | } |
||
| 70 | |||
| 71 | 2 | return $this->originResourceDO; |
|
| 72 | } |
||
| 73 | |||
| 86 | } |
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.