FunctionWrappersCache   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A has() 4 4 1
A get() 8 8 2
A put() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Wrappers\FunctionComponents;
17
18
19
use OverflowException;
20
use Pinepain\ObjectMaps\ObjectMapInterface;
21
use UnexpectedValueException;
22
use V8\FunctionObject;
23
24
25 View Code Duplication
class FunctionWrappersCache implements FunctionWrappersCacheInterface
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...
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