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