ResourceValue::type()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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
use ErrorException;
10
use TypeError;
11
12
use function gettype;
13
use function is_resource;
14
15
/**
16
 * Class ResourceValue.
17
 */
18
abstract class ResourceValue extends AbstractValue implements ResourceValueInterface
19
{
20
    /**
21
     * ResourceValue constructor.
22
     *
23
     * @param mixed $value
24
     */
25 8
    public function __construct($value)
26
    {
27 8
        if (false === is_resource($value)) {
28 1
            throw new TypeError(
29
                'Argument 1 passed to drupol\valuewrapper\Resource\ResourceValue::__construct()' .
30 1
                ' must be of the type Resource, ' . gettype($value) . ' given.'
31
            );
32
        }
33
34 7
        parent::__construct($value);
35 7
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function equals(ValueInterface $item, bool $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 2
    public function type(): string
57
    {
58 2
        return get_resource_type($this->value());
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 1
    public function unserialize($serialized)
65
    {
66 1
        throw new ErrorException('Unsupported method.');
67
    }
68
}
69