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

ResourceValue::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 4
cts 6
cp 0.6667
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.1481
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