Conditions | 13 |
Paths | 444 |
Total Lines | 50 |
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 |
||
40 | public function actionIndex() |
||
41 | { |
||
42 | // opcache reset should run in web context, but might be helpfull as well. |
||
43 | if (function_exists('opcache_reset')) { |
||
44 | @opcache_reset(); |
||
|
|||
45 | } |
||
46 | |||
47 | $error = false; |
||
48 | |||
49 | @chdir(Yii::getAlias('@app')); |
||
50 | |||
51 | $this->output('The directory the health commands is applying to: ' . Yii::getAlias('@app')); |
||
52 | |||
53 | foreach ($this->folders as $folder => $writable) { |
||
54 | $mode = ($writable) ? 0777 : 0775; |
||
55 | if (!file_exists($folder)) { |
||
56 | if (FileHelper::createDirectory($folder, $mode)) { |
||
57 | $this->outputSuccess("$folder: successfully created directory"); |
||
58 | } else { |
||
59 | $error = true; |
||
60 | $this->outputError("$folder: unable to create directory"); |
||
61 | } |
||
62 | } else { |
||
63 | $this->outputInfo("$folder: directory exists already"); |
||
64 | } |
||
65 | |||
66 | if ($writable && !is_writable($folder)) { |
||
67 | $this->outputInfo("$folder: is not writeable, try to set mode '$mode'."); |
||
68 | @chmod($folder, $mode); |
||
69 | } |
||
70 | |||
71 | if ($writable) { |
||
72 | if (!is_writable($folder)) { |
||
73 | $error = true; |
||
74 | $this->outputError("$folder: is not writable, please change permissions."); |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | |||
79 | foreach ($this->files as $file) { |
||
80 | if (file_exists($file)) { |
||
81 | $this->outputInfo("$file: file exists."); |
||
82 | } else { |
||
83 | $error = true; |
||
84 | $this->outputError("$file: file does not exists!"); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | return $error ? $this->outputError('Health check found errors!') : $this->outputSuccess('O.K.'); |
||
89 | } |
||
90 | |||
108 |
If you suppress an error, we recommend checking for the error condition explicitly: