Completed
Push — master ( e33bed...05c971 )
by Pol
02:19
created

ResourceValue   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 12
loc 36
ccs 4
cts 10
cp 0.4
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 2
A hash() 0 4 1
A doHash() 0 4 1

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
2
3
namespace drupol\valuewrapper\Resource;
4
5
use drupol\valuewrapper\AbstractValue;
6
7
class ResourceValue extends AbstractValue
8
{
9
    /**
10
     * ResourceValue constructor.
11
     *
12
     * @param mixed $value
13
     */
14 1 View Code Duplication
    public function __construct($value)
0 ignored issues
show
Duplication introduced by
This method 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...
15
    {
16
        // We cannot use type hint here because of this: https://3v4l.org/W9F7o
17 1
        if (false === \is_resource($value)) {
18
            throw new \TypeError(
19
                'Argument 1 passed to drupol\valuewrapper\Resource\ResourceValue::__construct()' .
0 ignored issues
show
Unused Code introduced by
The call to TypeError::__construct() has too many arguments starting with 'Argument 1 passed to dr...ype($value) . ' given.'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
20
                'must be of the type Resource, ' . gettype($value) . ' given.'
21
            );
22
        }
23
24 1
        parent::__construct($value);
25 1
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function hash(): string
31
    {
32
        return $this->doHash(\spl_object_hash($this->get()));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function doHash(string $string) : string
39
    {
40
        return \sha1(gettype($this->get()) . get_class($this->get()) . $string);
41
    }
42
}
43