Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
DeliveryNamespaceRegistry
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2021 (original work) Open Assessment Technologies SA;
19 *
20 * @author Sergei Mikhailov <sergei.mikhailov@taotesting.com>
21 */
22
23declare(strict_types=1);
24
25namespace oat\taoDeliveryRdf\model\Delivery\DataAccess;
26
27use InvalidArgumentException;
28use oat\tao\model\service\InjectionAwareService;
29use oat\taoDeliveryRdf\model\Delivery\Business\Domain\DeliveryNamespace;
30use oat\taoDeliveryRdf\model\Delivery\Business\Contract\DeliveryNamespaceRegistryInterface;
31
32final class DeliveryNamespaceRegistry extends InjectionAwareService implements DeliveryNamespaceRegistryInterface
33{
34    /** @var DeliveryNamespace */
35    private $deliveryNamespace;
36    /** @var ?DeliveryNamespace */
37    private $localNamespace;
38
39    public function __construct(DeliveryNamespace $localNamespace, DeliveryNamespace $deliveryNamespace = null)
40    {
41        parent::__construct();
42
43        $this->localNamespace    = $localNamespace;
44        $this->deliveryNamespace = $deliveryNamespace;
45
46        $this->validate();
47    }
48
49    private function validate(): void
50    {
51        if (null === $this->deliveryNamespace) {
52            return;
53        }
54
55        if ($this->deliveryNamespace->equals($this->localNamespace)) {
56            throw new InvalidArgumentException(
57                "Overridden namespace value must be different from a local one, \"$this->deliveryNamespace\" given"
58            );
59        }
60    }
61
62    public function get(): ?DeliveryNamespace
63    {
64        return $this->deliveryNamespace;
65    }
66}