Completed
Pull Request — master (#404)
by De Cramer
03:04
created

AbstractServerInformation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\ServerInformation\Services\ServerInformation;
4
5
use eXpansion\Bundle\ServerInformation\Services\ServerInformationInterface;
6
use eXpansion\Bundle\ServerInformation\Ui\Factory\ServerInformationLineFactory;
7
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups;
8
9
abstract class AbstractServerInformation implements ServerInformationInterface
10
{
11
    /** @var ServerInformationLineFactory */
12
    protected $serverInformationLineFactory;
13
14
    /** @var AdminGroups */
15
    protected $adminGroupHelper;
16
17
    /** @var string|null */
18
    protected $requiredPermission;
19
20
    /**
21
     * AbstractServerInformation constructor.
22
     *
23
     * @param ServerInformationLineFactory\ $serverInformationLineFactory
24
     * @param AdminGroups $adminGroupHelper
25
     * @param string|null $requiredPermission
26
     */
27
    public function __construct(
28
        ServerInformationLineFactory $serverInformationLineFactory,
29
        AdminGroups $adminGroupHelper,
30
        $requiredPermission = null
31
    ) {
32
        $this->serverInformationLineFactory = $serverInformationLineFactory;
33
        $this->adminGroupHelper = $adminGroupHelper;
34
        $this->requiredPermission = $requiredPermission;
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function canShow(string $login): bool
41
    {
42
        if (is_null($this->requiredPermission)) {
43
            return true;
44
        }
45
46
        return $this->adminGroupHelper->hasPermission($login, $this->requiredPermission);
47
    }
48
}
49