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