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

AbstractServerInformation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 40
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A canShow() 0 8 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