| Conditions | 16 |
| Paths | 3 |
| Total Lines | 44 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 34 |
| CRAP Score | 16.0059 |
| 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 |
||
| 30 | 13 | public function __invoke($byPathOnly = false) |
|
| 31 | { |
||
| 32 | 13 | $uuid = $this->resourceDO->getUuid(); |
|
|
1 ignored issue
–
show
|
|||
| 33 | 13 | $type = $this->resourceDO->getType(); |
|
|
1 ignored issue
–
show
|
|||
| 34 | 13 | $variant = $this->resourceDO->getVariant(); |
|
|
1 ignored issue
–
show
|
|||
| 35 | 13 | $version = $this->resourceDO->getVersion(); |
|
|
1 ignored issue
–
show
|
|||
| 36 | 13 | $baseDir = $this->resourceDO->getBaseDirectory(); |
|
|
1 ignored issue
–
show
|
|||
| 37 | 13 | $namespace = $this->resourceDO->getNamespace(); |
|
| 38 | 13 | $filePath = $this->resourceDO->getFilePath(); |
|
|
1 ignored issue
–
show
|
|||
| 39 | 13 | if (!$uuid || !$type || !$baseDir || !$filePath) { |
|
| 40 | 1 | throw new CommandErrorException('Cannot destroy the empty resource'); |
|
| 41 | } |
||
| 42 | 12 | if ($byPathOnly) { |
|
| 43 | 6 | $this->deleteFile($filePath); |
|
| 44 | 6 | } else { |
|
| 45 | 6 | $command = new FindResourceOptionsCommand($this->resourceDO, $this->filesystem); |
|
| 46 | 6 | $result = $command(); |
|
|
1 ignored issue
–
show
|
|||
| 47 | 6 | foreach ($result as $item) { |
|
| 48 | if ( |
||
| 49 | 6 | $item[ResourceDOAbstract::TOKEN_TYPE] !== $type |
|
| 50 | 6 | || $item['filename'] !== $uuid |
|
| 51 | 6 | || ($namespace && ($item[ResourceDOAbstract::TOKEN_NAMESPACE] !== $namespace)) |
|
| 52 | 6 | ) { |
|
| 53 | continue; |
||
| 54 | } |
||
| 55 | 6 | if ($version !== ResourceDOInterface::DEFAULT_VERSION) { |
|
| 56 | if ( |
||
| 57 | 2 | $variant === $item[ResourceDOAbstract::TOKEN_VARIANT] // delete versions only for current variant |
|
| 58 | 2 | && $version === (int)$item[ResourceDOAbstract::TOKEN_VERSION] |
|
| 59 | 2 | ) { |
|
| 60 | 2 | $this->deleteFile($item['path']); |
|
| 61 | 2 | } |
|
| 62 | 6 | } elseif ($variant !== ResourceDOInterface::DEFAULT_VARIANT) { |
|
| 63 | 2 | if ($variant === $item[ResourceDOAbstract::TOKEN_VARIANT]) { |
|
| 64 | 2 | $this->deleteFile($item['path']); |
|
| 65 | 2 | } |
|
| 66 | 2 | } else { |
|
| 67 | 2 | $this->deleteFile($item['path']); |
|
| 68 | } |
||
| 69 | 6 | } |
|
| 70 | } |
||
| 71 | |||
| 72 | 12 | return $this->resourceDO; |
|
| 73 | } |
||
| 74 | |||
| 82 | } |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.