| Conditions | 7 |
| Paths | 10 |
| Total Lines | 59 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 54 | public function process() |
||
| 55 | { |
||
| 56 | $this->setProcessor(); |
||
| 57 | |||
| 58 | call_user_func_array( |
||
| 59 | $this->builder->getMessageCb(), |
||
| 60 | ['POSTPROCESS', sprintf('Post-processing %s', $this->type)] |
||
| 61 | ); |
||
| 62 | |||
| 63 | $extensions = $this->builder->getConfig()->get(sprintf('postprocess.%s.ext', $this->type)); |
||
| 64 | if (empty($extensions)) { |
||
| 65 | throw new Exception(sprintf('The config key "postprocess.%s.ext" is empty', $this->type)); |
||
| 66 | } |
||
| 67 | |||
| 68 | $files = Finder::create() |
||
| 69 | ->files() |
||
| 70 | ->in($this->builder->getConfig()->getOutputPath()) |
||
| 71 | ->name('/\.('.implode('|', $extensions).')$/') |
||
| 72 | ->notName('/\.min\.('.implode('|', $extensions).')$/') |
||
| 73 | ->sortByName(true); |
||
| 74 | $max = count($files); |
||
| 75 | |||
| 76 | if ($max <= 0) { |
||
| 77 | $message = 'No files'; |
||
| 78 | call_user_func_array($this->builder->getMessageCb(), ['POSTPROCESS_PROGRESS', $message]); |
||
| 79 | |||
| 80 | return; |
||
| 81 | } |
||
| 82 | |||
| 83 | $count = 0; |
||
| 84 | $postprocessed = 0; |
||
| 85 | |||
| 86 | /** @var \Symfony\Component\Finder\SplFileInfo $file */ |
||
| 87 | foreach ($files as $file) { |
||
| 88 | $count++; |
||
| 89 | $sizeBefore = $file->getSize(); |
||
| 90 | $message = $file->getRelativePathname(); |
||
| 91 | |||
| 92 | $cache = new Cache($this->builder, 'postprocess', $this->config->getOutputPath()); |
||
| 93 | if (!$cache->isExists($file->getPathname())) { |
||
| 94 | $hash = $cache->getHash($file->getPathname()); |
||
| 95 | $this->processFile($file); |
||
| 96 | $postprocessed++; |
||
| 97 | $sizeAfter = $file->getSize(); |
||
| 98 | if ($sizeAfter < $sizeBefore) { |
||
| 99 | $message = sprintf( |
||
| 100 | '%s (%s Ko -> %s Ko)', |
||
| 101 | $file->getRelativePathname(), |
||
| 102 | ceil($sizeBefore / 1000), |
||
| 103 | ceil($sizeAfter / 1000) |
||
| 104 | ); |
||
| 105 | } |
||
| 106 | $cache->save($file->getPathname(), $hash); |
||
| 107 | } |
||
| 108 | call_user_func_array($this->builder->getMessageCb(), ['POSTPROCESS_PROGRESS', $message, $count, $max]); |
||
| 109 | } |
||
| 110 | if ($postprocessed == 0) { |
||
|
|
|||
| 111 | $message = '> Nothing to do'; |
||
| 112 | call_user_func_array($this->builder->getMessageCb(), ['POSTPROCESS_PROGRESS', $message]); |
||
| 113 | } |
||
| 155 |