Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
LdapConfiguration
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
7 / 7
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
3
 getMainServer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMainPort
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMainUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMainPassword
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMainBase
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getServers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * LDAP configuration class
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2023-2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2023-04-30
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Configuration;
21
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}