Conditions | 5 |
Paths | 4 |
Total Lines | 32 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | public function collect(): array |
||
16 | { |
||
17 | $passwdFile = self::PASSWORD_FILE; |
||
18 | |||
19 | $runner = Runner::getInstance(); |
||
20 | |||
21 | if (!$runner->fileExists($passwdFile) || !File::getInstance()->isReadable($passwdFile)) { |
||
22 | return []; |
||
23 | } |
||
24 | |||
25 | $users = []; |
||
26 | |||
27 | foreach (File::getInstance()->getContents($passwdFile, true) as $line) { |
||
28 | $parts = explode(':', trim($line)); |
||
29 | |||
30 | if (count($parts) < 7) { |
||
31 | continue; |
||
32 | } |
||
33 | |||
34 | list($username, $password, $uid, $gid, $comment, $home, $shell) = $parts; |
||
35 | |||
36 | $users[] = [ |
||
37 | 'username' => $username, |
||
38 | 'uid' => (int)$uid, |
||
39 | 'gid' => (int)$gid, |
||
40 | 'comment' => $comment, |
||
41 | 'home' => $home, |
||
42 | 'shell' => $shell, |
||
43 | ]; |
||
44 | } |
||
45 | |||
46 | return ['users' => $users]; |
||
47 | } |
||
50 |