Conditions | 7 |
Paths | 12 |
Total Lines | 62 |
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 |
||
52 | public function process() |
||
53 | { |
||
54 | $this->setProcessor(); |
||
55 | |||
56 | call_user_func_array($this->builder->getMessageCb(), ['OPTIMIZE', sprintf('Optimizing %s', $this->type)]); |
||
57 | |||
58 | $extensions = $this->builder->getConfig()->get(sprintf('optimize.%s.ext', $this->type)); |
||
59 | if (empty($extensions)) { |
||
60 | throw new \Exception(sprintf('The config key "optimize.%s.ext" is empty', $this->type)); |
||
61 | } |
||
62 | |||
63 | $files = Finder::create() |
||
64 | ->files() |
||
65 | ->in($this->builder->getConfig()->getOutputPath()) |
||
66 | ->name('/\.('.implode('|', $extensions).')$/') |
||
67 | ->notName('/\.min\.('.implode('|', $extensions).')$/') |
||
68 | ->sortByName(true); |
||
69 | $max = count($files); |
||
70 | |||
71 | if ($max <= 0) { |
||
72 | $message = 'No files'; |
||
73 | call_user_func_array($this->builder->getMessageCb(), ['OPTIMIZE_PROGRESS', $message]); |
||
74 | |||
75 | return; |
||
76 | } |
||
77 | |||
78 | $count = 0; |
||
79 | $optimized = 0; |
||
80 | |||
81 | /* @var $file \Symfony\Component\Finder\SplFileInfo */ |
||
82 | foreach ($files as $file) { |
||
83 | $count++; |
||
84 | |||
85 | $sizeBefore = $file->getSize(); |
||
86 | |||
87 | $this->processFile($file); |
||
88 | |||
89 | $sizeAfter = $file->getSize(); |
||
90 | |||
91 | $subpath = \Cecil\Util::getFS()->makePathRelative( |
||
92 | $file->getPath(), |
||
93 | $this->builder->getConfig()->getOutputPath() |
||
94 | ); |
||
95 | $subpath = trim($subpath, './'); |
||
96 | $path = $subpath ? $subpath.'/'.$file->getFilename() : $file->getFilename(); |
||
97 | |||
98 | $message = sprintf( |
||
99 | '%s: %s Ko -> %s Ko', |
||
100 | $path, |
||
101 | ceil($sizeBefore / 1000), |
||
102 | ceil($sizeAfter / 1000) |
||
103 | ); |
||
104 | call_user_func_array($this->builder->getMessageCb(), ['OPTIMIZE_PROGRESS', $message, $count, $max]); |
||
105 | if ($sizeAfter < $sizeBefore) { |
||
106 | $optimized++; |
||
107 | } |
||
108 | } |
||
109 | if ($optimized == 0) { |
||
110 | $message = 'Nothing to do'; |
||
111 | call_user_func_array($this->builder->getMessageCb(), ['OPTIMIZE_PROGRESS', $message]); |
||
112 | } |
||
113 | } |
||
114 | |||
127 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.