Lines 100.00% 29 / 29
Methods 100.00% 7 / 7
Classes 100.00% 1 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 23 / 23 100.00% 1 / 1 3
 getMainServer 100.00% 1 / 1 100.00% 1 / 1 1
 getMainPort 100.00% 1 / 1 100.00% 1 / 1 1
 getMainUser 100.00% 1 / 1 100.00% 1 / 1 1
 getMainPassword 100.00% 1 / 1 100.00% 1 / 1 1
 getMainBase 100.00% 1 / 1 100.00% 1 / 1 1
 getServers 100.00% 1 / 1 100.00% 1 / 1 1
22class LdapConfiguration
23{
24    private readonly string $mainServer;
25
26    private readonly int $mainPort;
27
28    private readonly string $mainUser;
29
30    private readonly string $mainPassword;
31
32    private readonly string $mainBase;
33
34    private array $servers = [];
35
36    public function __construct(string $filename)
37    {
38        $PMF_LDAP = [
39            'ldap_server' => '',
40            'ldap_port' => 389,
41            'ldap_user' => '',
42            'ldap_password' => '',
43            'ldap_base' => '',
44        ];
45
46        include $filename;
47
48        $this->mainServer = $PMF_LDAP['ldap_server'];
49        $this->mainPort = (int) $PMF_LDAP['ldap_port'];
50        $this->mainUser = $PMF_LDAP['ldap_user'];
51        $this->mainPassword = $PMF_LDAP['ldap_password'];
52        $this->mainBase = $PMF_LDAP['ldap_base'];
53
54        foreach ($PMF_LDAP as $key => $server) {
55            /* @mago-expect analysis:impossible-type-comparison - multi-server config files append array entries to $PMF_LDAP */
56            if (!is_array($server)) {
57                continue;
58            }
59
60            $this->servers[$key] = [
61                'server' => $server['ldap_server'],
62                'port' => (int) $server['ldap_port'],
63                'user' => $server['ldap_user'],
64                'password' => $server['ldap_password'],
65                'base' => $server['ldap_base'],
66            ];
67        }
68    }
69
70    public function getMainServer(): string
71    {
72        return $this->mainServer;
73    }
74
75    public function getMainPort(): int
76    {
77        return $this->mainPort;
78    }
79
80    public function getMainUser(): string
81    {
82        return $this->mainUser;
83    }
84
85    public function getMainPassword(): string
86    {
87        return $this->mainPassword;
88    }
89
90    public function getMainBase(): string
91    {
92        return $this->mainBase;
93    }
94
95    public function getServers(): array
96    {
97        return $this->servers;
98    }
99}