NativeModulesRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 34
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A has() 0 4 1
A get() 0 8 2
A put() 0 8 2
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\Modules\Repositories;
17
18
19
use OverflowException;
20
use Pinepain\JsSandbox\Modules\NativeModulePrototypeInterface;
21
use Pinepain\JsSandbox\Modules\SourceModulePrototype;
22
use UnexpectedValueException;
23
24
25
class NativeModulesRepository implements NativeModulesRepositoryInterface
26
{
27
    /**
28
     * @var NativeModulePrototypeInterface[]
29
     */
30
    private $modules = [];
31
32
    public function __construct()
33
    {
34
    }
35
36
    public function has($module): bool
37
    {
38
        return isset($this->modules[$module]);
39
    }
40
41
    public function get($module): NativeModulePrototypeInterface
42
    {
43
        if (!isset($this->modules[$module])) {
44
            throw new UnexpectedValueException('Native module not found');
45
        }
46
47
        return $this->modules[$module];
48
    }
49
50
    public function put($module, NativeModulePrototypeInterface $value)
51
    {
52
        if (isset($this->modules[$module])) {
53
            throw new OverflowException('Native module mapping already exists');
54
        }
55
56
        $this->modules[$module] = $value;
57
    }
58
}
59