Conditions | 10 |
Paths | 20 |
Total Lines | 27 |
Code Lines | 14 |
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 |
||
48 | public function init() |
||
49 | { |
||
50 | $cachePath = empty($this->cachePath) ? false : Yii::getAlias($this->cachePath); |
||
51 | |||
52 | if (!empty($cachePath) && !file_exists($cachePath)) { |
||
53 | FileHelper::createDirectory($cachePath); |
||
|
|||
54 | } |
||
55 | |||
56 | if (!empty($cachePath) && !is_readable($cachePath)) { |
||
57 | throw new Exception(\Yii::t('app', 'Pug cache path is not readable.')); |
||
58 | } |
||
59 | |||
60 | if (!empty($cachePath) && !is_writeable($cachePath)) { |
||
61 | throw new Exception(\Yii::t('app', 'Pug cache path is not writable.')); |
||
62 | } |
||
63 | |||
64 | $this->pug = new Pug(array_merge([ |
||
65 | 'cache' => $cachePath, |
||
66 | ], $this->options)); |
||
67 | |||
68 | // Adding custom filters |
||
69 | if (!empty($this->filters)) { |
||
70 | foreach ($this->filters as $name => $handler) { |
||
71 | $this->addFilter($name, $handler); |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | |||
103 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.