Completed
Push — master ( fc23f2...1703ac )
by Pol
15:28 queued 14:05
created

ResourceValue::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 11
ccs 4
cts 6
cp 0.6667
crap 2.1481
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\valuewrapper\Resource;
6
7
use drupol\valuewrapper\AbstractValue;
8
9
abstract class ResourceValue extends AbstractValue
10
{
11
    /**
12
     * ResourceValue constructor.
13
     *
14
     * @param mixed $value
15
     */
16 2
    public function __construct($value)
17
    {
18 2
        if (false == \is_resource($value)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

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