| Conditions | 11 |
| Paths | 8 |
| Total Lines | 52 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 11.1043 |
| 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 |
||
| 25 | 2 | public function load($file) |
|
| 26 | { |
||
| 27 | 2 | if (!file_exists($file) || !is_readable($file)) { |
|
| 28 | throw new Exception("File `$file` doesn't exists or doesn't readable."); |
||
| 29 | } |
||
| 30 | |||
| 31 | 2 | $data = Yaml::parse(file_get_contents($file)); |
|
| 32 | |||
| 33 | 2 | if (!is_array($data)) { |
|
| 34 | throw new Exception("Hosts file `$file` should contains array of hosts."); |
||
| 35 | } |
||
| 36 | |||
| 37 | 2 | foreach ($data as $hostname => $config) { |
|
| 38 | 2 | if (preg_match('/^\./', $hostname)) { |
|
| 39 | 2 | continue; |
|
| 40 | } |
||
| 41 | |||
| 42 | 2 | if (isset($config['local'])) { |
|
| 43 | 2 | $host = new Localhost($hostname); |
|
| 44 | } else { |
||
| 45 | 2 | $host = new Host($hostname); |
|
| 46 | $methods = [ |
||
| 47 | 2 | 'hostname', |
|
| 48 | 'user', |
||
| 49 | 'port', |
||
| 50 | 'configFile', |
||
| 51 | 'identityFile', |
||
| 52 | 'forwardAgent', |
||
| 53 | 'multiplexing', |
||
| 54 | 'sshOptions', |
||
| 55 | 'sshFlags', |
||
| 56 | 'shellCommand', |
||
| 57 | ]; |
||
| 58 | |||
| 59 | 2 | foreach ($methods as $method) { |
|
| 60 | 2 | if (isset($config[$method])) { |
|
| 61 | 2 | $host->$method($config[$method]); |
|
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | 2 | if (is_array($config)) { |
|
| 67 | 2 | foreach ($config as $name => $value) { |
|
| 68 | 2 | $host->set($name, $value); |
|
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | 2 | $this->hosts[$hostname] = $host; |
|
| 73 | } |
||
| 74 | |||
| 75 | 2 | return $this; |
|
| 76 | } |
||
| 77 | |||
| 86 |