Completed
Push — master ( e7c2bb...340eef )
by Pol
14:36
created

ResourceValue::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\valuewrapper\Resource;
6
7
use drupol\valuewrapper\AbstractValue;
8
use drupol\valuewrapper\ValueInterface;
9
10
/**
11
 * Class ResourceValue
12
 */
13
abstract class ResourceValue extends AbstractValue implements ResourceValueInterface
14
{
15
    /**
16
     * ResourceValue constructor.
17
     *
18
     * @param mixed $value
19
     */
20 7
    public function __construct($value)
21
    {
22 7
        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...
23 1
            throw new \TypeError(
24
                '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...
25 1
                'must be of the type Resource, ' . gettype($value) . ' given.'
26
            );
27
        }
28
29 6
        parent::__construct($value);
30 6
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    abstract public function hash(): string;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function equals(ValueInterface $item, $strict = true) : bool
41
    {
42 1
        return $this->hash() == $item->hash();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 1
    public function serialize()
49
    {
50 1
        throw new \ErrorException('Unsupported method.');
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    public function unserialize($serialized)
57
    {
58 1
        throw new \ErrorException('Unsupported method.');
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function type(): string
65
    {
66
        return \get_resource_type($this->value());
67
    }
68
}
69