Completed
Push — master ( 344583...2d30d0 )
by Bogdan
11s
created

DecoratorsCollection::put()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/js-sandbox PHP library.
5
 *
6
 * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7
 *
8
 * Licensed under the MIT license: http://opensource.org/licenses/MIT
9
 *
10
 * For the full copyright and license information, please view the
11
 * LICENSE file that was distributed with this source or visit
12
 * http://opensource.org/licenses/MIT
13
 */
14
15
16
namespace Pinepain\JsSandbox\Decorators;
17
18
19
use OutOfBoundsException;
20
use OverflowException;
21
use Pinepain\JsSandbox\Decorators\Definitions\DecoratorInterface;
22
23
24 View Code Duplication
class DecoratorsCollection implements DecoratorsCollectionInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
{
26
    protected $decorators = [];
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function get(string $name): DecoratorInterface
32
    {
33
        if (!isset($this->decorators[$name])) {
34
            throw new OutOfBoundsException("Decorator '{$name}' not found");
35
        }
36
37
        return $this->decorators[$name];
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function put(string $name, DecoratorInterface $extractor)
44
    {
45
        if (isset($this->decorators[$name])) {
46
            throw new OverflowException("Decorator with the same name ('{$name}') already exists");
47
        }
48
        $this->decorators[$name] = $extractor;
49
    }
50
}
51