Conditions | 7 |
Paths | 12 |
Total Lines | 60 |
Code Lines | 39 |
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(), ['OPTIMIZE', sprintf('Optimizing %s', $this->type)]); |
||
56 | |||
57 | $extensions = $this->builder->getConfig()->get(sprintf('optimize.%s.ext', $this->type)); |
||
58 | if (empty($extensions)) { |
||
59 | throw new Exception(sprintf('The config key "optimize.%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(), ['OPTIMIZE_PROGRESS', $message]); |
||
73 | |||
74 | return; |
||
75 | } |
||
76 | |||
77 | $count = 0; |
||
78 | $optimized = 0; |
||
79 | |||
80 | /* @var $file \Symfony\Component\Finder\SplFileInfo */ |
||
81 | foreach ($files as $file) { |
||
82 | $count++; |
||
83 | |||
84 | $sizeBefore = $file->getSize(); |
||
85 | |||
86 | $this->processFile($file); |
||
87 | |||
88 | $sizeAfter = $file->getSize(); |
||
89 | |||
90 | $subpath = \Cecil\Util::getFS()->makePathRelative( |
||
91 | $file->getPath(), |
||
92 | $this->builder->getConfig()->getOutputPath() |
||
93 | ); |
||
94 | $subpath = trim($subpath, './'); |
||
95 | $path = $subpath ? $subpath.'/'.$file->getFilename() : $file->getFilename(); |
||
96 | |||
97 | $message = sprintf( |
||
98 | '%s: %s Ko -> %s Ko', |
||
99 | $path, |
||
100 | ceil($sizeBefore / 1000), |
||
101 | ceil($sizeAfter / 1000) |
||
102 | ); |
||
103 | call_user_func_array($this->builder->getMessageCb(), ['OPTIMIZE_PROGRESS', $message, $count, $max]); |
||
104 | if ($sizeAfter < $sizeBefore) { |
||
105 | $optimized++; |
||
106 | } |
||
107 | } |
||
108 | if ($optimized == 0) { |
||
109 | $message = 'Nothing to do'; |
||
110 | call_user_func_array($this->builder->getMessageCb(), ['OPTIMIZE_PROGRESS', $message]); |
||
111 | } |
||
130 |