| Conditions | 7 |
| Paths | 6 |
| Total Lines | 58 |
| 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 |
||
| 49 | public function generateCommand($limit = 0, $offset = 0, $configuration = [], $verbose = false) |
||
| 50 | { |
||
| 51 | |||
| 52 | $this->checkEnvironment(); |
||
| 53 | |||
| 54 | foreach ($this->getStorageRepository()->findAll() as $storage) { |
||
| 55 | |||
| 56 | // TODO: Make me more flexible by passing thumbnail configuration. For now it will only generate thumbnails for the BE module. |
||
| 57 | |||
| 58 | $this->outputLine(); |
||
| 59 | $this->outputLine(sprintf('%s (%s)', $storage->getName(), $storage->getUid())); |
||
| 60 | $this->outputLine('--------------------------------------------'); |
||
| 61 | $this->outputLine(); |
||
| 62 | |||
| 63 | if ($storage->isOnline()) { |
||
| 64 | |||
| 65 | // For the CLI cause. |
||
| 66 | $storage->setEvaluatePermissions(false); |
||
| 67 | |||
| 68 | $thumbnailGenerator = $this->getThumbnailGenerator(); |
||
| 69 | $thumbnailGenerator |
||
| 70 | ->setStorage($storage) |
||
| 71 | ->setConfiguration($configuration) |
||
| 72 | ->generate($limit, $offset); |
||
| 73 | |||
| 74 | if ($verbose) { |
||
| 75 | $resultSet = $thumbnailGenerator->getResultSet(); |
||
| 76 | foreach ($resultSet as $result) { |
||
| 77 | $message = sprintf('* File "%s": %s %s', |
||
| 78 | $result['fileUid'], |
||
| 79 | $result['fileIdentifier'], |
||
| 80 | empty($result['thumbnailUri']) ? '' : ' -> ' . $result['thumbnailUri'] |
||
| 81 | ); |
||
| 82 | $this->outputLine($message); |
||
| 83 | } |
||
| 84 | $this->outputLine(); |
||
| 85 | } |
||
| 86 | |||
| 87 | $message = sprintf('Done! New generated %s thumbnail(s) from %s traversed file(s) of a total of %s files.', |
||
| 88 | $thumbnailGenerator->getNumberOfProcessedFiles(), |
||
| 89 | $thumbnailGenerator->getNumberOfTraversedFiles(), |
||
| 90 | $thumbnailGenerator->getTotalNumberOfFiles() |
||
| 91 | ); |
||
| 92 | $this->outputLine($message); |
||
| 93 | |||
| 94 | // Add warning message if missing files were found along the way. |
||
| 95 | if ($thumbnailGenerator->getNumberOfMissingFiles() > 0) { |
||
| 96 | |||
| 97 | $message = sprintf('ATTENTION! %s missing file(s) detected.', |
||
| 98 | $thumbnailGenerator->getNumberOfMissingFiles() |
||
| 99 | ); |
||
| 100 | $this->outputLine($message); |
||
| 101 | } |
||
| 102 | } else { |
||
| 103 | $this->outputLine('Storage is offline!'); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 158 |