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

ExtractorsObjectStore::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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\ObjectComponents;
17
18
19
use Pinepain\JsSandbox\Extractors\ObjectComponents\ExtractorsObjectStoreInterface;
20
21
use Pinepain\ObjectMaps\ObjectMapInterface;
22
23
use OverflowException;
24
use UnexpectedValueException;
25
26
use V8\ObjectValue;
27
28
29 View Code Duplication
class ExtractorsObjectStore implements ExtractorsObjectStoreInterface
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...
30
{
31
    /**
32
     * @var ObjectMapInterface
33
     */
34
    private $map;
35
36
    public function __construct(ObjectMapInterface $map)
37
    {
38
        $this->map = $map;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function has(ObjectValue $object): bool
45
    {
46
        return $this->map->has($object);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function get(ObjectValue $object)
53
    {
54
        if (!$this->map->has($object)) {
55
            throw new UnexpectedValueException('Object mapping not found');
56
        }
57
58
        return $this->map->get($object);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function put(ObjectValue $object, $value)
65
    {
66
        if ($this->map->has($object)) {
67
            throw new OverflowException('Object mapping already exists');
68
        }
69
70
        $this->map->put($object, $value);
71
    }
72
}
73