ResourceValue   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
eloc 9
c 3
b 0
f 0
dl 0
loc 49
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 3 1
A unserialize() 0 3 1
A __construct() 0 10 2
A equals() 0 3 1
A type() 0 3 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