| Conditions | 10 |
| Paths | 24 |
| Total Lines | 42 |
| 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 |
||
| 152 | private function addAdminsGuardToConfigFile() |
||
| 153 | { |
||
| 154 | $shouldAddGuardsSection = true; |
||
| 155 | if (config('auth.guards.admin')) { |
||
| 156 | $shouldAddGuardsSection = false; |
||
| 157 | $this->comment(' - guard [admin] already exist'); |
||
| 158 | } |
||
| 159 | |||
| 160 | $shouldAddProvidersSection = true; |
||
| 161 | if (config('auth.guards.providers.admins')) { |
||
| 162 | $shouldAddProvidersSection = false; |
||
| 163 | $this->comment(' - provider [admins] already exist'); |
||
| 164 | } |
||
| 165 | |||
| 166 | if (!$shouldAddGuardsSection && !$shouldAddProvidersSection) { |
||
| 167 | return; |
||
| 168 | } |
||
| 169 | |||
| 170 | $configFile = config_path('auth.php'); |
||
| 171 | |||
| 172 | $output = ''; |
||
| 173 | $file = new SplFileObject($configFile, 'r'); |
||
| 174 | foreach ($file as $lineNumber => $line) { |
||
| 175 | $output .= $line; |
||
| 176 | if ($line == " 'guards' => [\n" && $shouldAddGuardsSection) { |
||
| 177 | $output .= " 'admin' => [\n"; |
||
| 178 | $output .= " 'driver' => 'session',\n"; |
||
| 179 | $output .= " 'provider' => 'admins',\n"; |
||
| 180 | $output .= " ],\n\n"; |
||
| 181 | } |
||
| 182 | |||
| 183 | if ($line == " 'providers' => [\n" && $shouldAddProvidersSection) { |
||
| 184 | $output .= " 'admins' => [\n"; |
||
| 185 | $output .= " 'driver' => 'eloquent',\n"; |
||
| 186 | $output .= " 'model' => \Yaro\Jarboe\Models\Admin::class,\n"; |
||
| 187 | $output .= " ],\n\n"; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | $file = new SplFileObject($configFile, 'w+'); |
||
| 192 | $file->fwrite($output); |
||
| 193 | } |
||
| 194 | } |
||
| 195 |