Completed
Push — wip-public-release ( 7c11a5...54ec9d )
by Bogdan
05:19
created

ExtractorsCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 27
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A put() 0 7 2
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the pinepain/php-v8-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\Extractors;
17
18
19
use OutOfBoundsException;
20
use OverflowException;
21
use Pinepain\JsSandbox\Extractors\PlainExtractors\PlainExtractorInterface;
22
23
24
class ExtractorsCollection implements ExtractorsCollectionInterface
25
{
26
    protected $extractors = [];
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function get(string $name): PlainExtractorInterface
32
    {
33
        if (!isset($this->extractors[$name])) {
34
            throw new OutOfBoundsException("Extractor '{$name}' not found");
35
        }
36
37
        return $this->extractors[$name];
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function put(string $name, PlainExtractorInterface $extractor)
44
    {
45
        if (isset($this->extractors[$name])) {
46
            throw new OverflowException("Extractor with the same name ('{$name}') already exists");
47
        }
48
        $this->extractors[$name] = $extractor;
49
    }
50
}
51