Code Duplication    Length = 36-44 lines in 3 locations

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/Extractors/ObjectComponents/ExtractorsObjectStore.php 1 location

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

src/Wrappers/ObjectComponents/WrappersObjectStore.php 1 location

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