Conditions | 10 |
Paths | 20 |
Total Lines | 27 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
48 | $cachePath = empty($this->cachePath) ? false : Yii::getAlias($this->cachePath); |
||
49 | |||
50 | if (!empty($cachePath) && !file_exists($cachePath)) { |
||
51 | FileHelper::createDirectory($cachePath); |
||
|
|||
52 | } |
||
53 | |||
54 | if (!empty($cachePath) && !is_readable($cachePath)) { |
||
55 | throw new Exception(\Yii::t('app', 'Pug cache path is not readable.')); |
||
56 | } |
||
57 | |||
58 | if (!empty($cachePath) && !is_writeable($cachePath)) { |
||
59 | throw new Exception(\Yii::t('app', 'Pug cache path is not writable.')); |
||
60 | } |
||
61 | |||
62 | $this->pug = new Pug(array_merge([ |
||
63 | 'cache' => $cachePath, |
||
64 | 'expressionLanguage' => 'php' |
||
65 | ], $this->options)); |
||
66 | |||
67 | // Adding custom filters |
||
68 | if (!empty($this->filters)) { |
||
69 | foreach ($this->filters as $name => $handler) { |
||
70 | $this->addFilter($name, $handler); |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 | |||
75 | /** |
||
102 |
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.