Code Duplication    Length = 36-44 lines in 3 locations

src/Extractors/ObjectComponents/ExtractorsObjectStore.php 1 location

@@ 29-72 (lines=44) @@
26
use V8\ObjectValue;
27
28
29
class ExtractorsObjectStore implements ExtractorsObjectStoreInterface
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

src/Wrappers/FunctionComponents/FunctionWrappersCache.php 1 location

@@ 25-60 (lines=36) @@
22
use V8\FunctionObject;
23
24
25
class FunctionWrappersCache implements FunctionWrappersCacheInterface
26
{
27
    /**
28
     * @var ObjectMapInterface
29
     */
30
    private $map;
31
32
    public function __construct(ObjectMapInterface $map)
33
    {
34
        // NOTE: map should be a weak values map
35
        $this->map = $map;
36
    }
37
38
    public function has($object): bool
39
    {
40
        return $this->map->has($object);
41
    }
42
43
    public function get($object): FunctionObject
44
    {
45
        if (!$this->map->has($object)) {
46
            throw new UnexpectedValueException('FunctionObject mapping not found');
47
        }
48
49
        return $this->map->get($object);
50
    }
51
52
    public function put($object, FunctionObject $value)
53
    {
54
        if ($this->map->has($object)) {
55
            throw new OverflowException('FunctionObject mapping already exists');
56
        }
57
58
        $this->map->put($object, $value);
59
    }
60
}
61

src/Wrappers/ObjectComponents/WrappersObjectStore.php 1 location

@@ 27-70 (lines=44) @@
24
use V8\ObjectValue;
25
26
27
class WrappersObjectStore implements WrappersObjectStoreInterface
28
{
29
    /**
30
     * @var ObjectMapInterface
31
     */
32
    private $map;
33
34
    public function __construct(ObjectMapInterface $map)
35
    {
36
        $this->map = $map;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function has($object): bool
43
    {
44
        return $this->map->has($object);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function get($object): ObjectValue
51
    {
52
        if (!$this->map->has($object)) {
53
            throw new UnexpectedValueException('Object mapping not found');
54
        }
55
56
        return $this->map->get($object);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function put($object, ObjectValue $value)
63
    {
64
        if ($this->map->has($object)) {
65
            throw new OverflowException('Object mapping already exists');
66
        }
67
68
        $this->map->put($object, $value);
69
    }
70
}
71