| Conditions | 10 |
| Paths | 35 |
| Total Lines | 43 |
| Code Lines | 25 |
| 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 |
||
| 68 | function checkSshKeyOnlyLogin(): array |
||
| 69 | { |
||
| 70 | $result = ['supported' => false, 'enforced' => false]; |
||
| 71 | |||
| 72 | if (stripos(strtolower(System::getInstance()->getPlatform()), 'linux') === false) { |
||
| 73 | return $result; |
||
| 74 | } |
||
| 75 | |||
| 76 | $runner = Runner::getInstance(); |
||
| 77 | |||
| 78 | $configPath = '/etc/ssh/sshd_config'; |
||
| 79 | if (!$runner->fileExists($configPath)) { |
||
| 80 | return $result; |
||
| 81 | } |
||
| 82 | |||
| 83 | $result['supported'] = true; |
||
| 84 | |||
| 85 | $config = $runner->getFileContents($configPath); |
||
| 86 | if ($config === false) { |
||
| 87 | return $result; |
||
| 88 | } |
||
| 89 | |||
| 90 | $lines = preg_split('/\r\n|\r|\n/', $config); |
||
| 91 | $settings = []; |
||
| 92 | |||
| 93 | foreach ($lines as $line) { |
||
| 94 | $line = trim(preg_replace('/#.*/', '', $line)); // Kommentare entfernen |
||
| 95 | if ($line === '') continue; |
||
| 96 | |||
| 97 | if (preg_match('/^\s*(\w+)\s+(yes|no)\s*$/i', $line, $matches)) { |
||
| 98 | $key = strtolower($matches[1]); |
||
| 99 | $value = strtolower($matches[2]); |
||
| 100 | $settings[$key] = $value; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | $passwordOff = isset($settings['passwordauthentication']) && $settings['passwordauthentication'] === 'no'; |
||
| 105 | $challengeOff = isset($settings['challengeresponseauthentication']) && $settings['challengeresponseauthentication'] === 'no'; |
||
| 106 | $usePamOff = isset($settings['usepam']) && $settings['usepam'] === 'no'; |
||
| 107 | |||
| 108 | $result['enforced'] = $passwordOff; // && $challengeOff && $usePamOff; |
||
| 109 | |||
| 110 | return $result; |
||
| 111 | } |
||
| 113 |