Completed
Push — master ( 9c95f5...e428dc )
by Paweł
06:06
created

AbstractScopeContext::setScopeOwner()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Settings Bundle.
7
 *
8
 * Copyright 2017 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2017 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\SettingsBundle\Context;
18
19
use SWP\Bundle\SettingsBundle\Model\SettingsOwnerInterface;
20
21
abstract class AbstractScopeContext implements ScopeContextInterface
22
{
23
    protected $scopeOwners = [];
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getScopesOwners(): array
29
    {
30
        return $this->scopeOwners;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function setScopeOwner(string $scope, SettingsOwnerInterface $owner)
37
    {
38
        if (in_array($scope, $this->getScopes())) {
39
            $this->scopeOwners[$scope] = $owner;
40
41
            return $owner;
42
        }
43
    }
44
45
    /**
46
     * @param string $scope
47
     *
48
     * @return SettingsOwnerInterface|bool
49
     */
50
    public function getScopeOwner(string $scope)
51
    {
52
        if (array_key_exists($scope, $this->scopeOwners)) {
53
            return $this->scopeOwners[$scope];
54
        }
55
56
        return null;
57
    }
58
}
59