GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ac587f...53bcfa )
by SignpostMarv
07:07
created

AbstractDaftObjectRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
* Base daft objects.
4
*
5
* @author SignpostMarv
6
*/
7
declare(strict_types=1);
8
9
namespace SignpostMarv\DaftObject;
10
11
abstract class AbstractDaftObjectRepository implements DaftObjectRepository
12
{
13
    /**
14
    * @var DefinesOwnIdPropertiesInterface[]
15
    */
16
    protected $memory = [];
17
18
    /**
19
    * @var array<string, array<string, mixed>>
20
    */
21
    protected $data = [];
22
23
    /**
24
    * @var string
25
    */
26
    protected $type;
27
28
    protected function __construct(string $type)
29
    {
30
        $this->type = $type;
31
    }
32
33
    public function ForgetDaftObject(DefinesOwnIdPropertiesInterface $object) : void
34
    {
35
        static::ThrowIfNotType($object, $this->type, 1, __FUNCTION__);
36
37
        $id = [];
38
39
        foreach ($object::DaftObjectIdProperties() as $prop) {
40
            $id[] = $object->$prop;
41
        }
42
43
        $this->ForgetDaftObjectById($id);
44
    }
45
46
    public function RemoveDaftObject(DefinesOwnIdPropertiesInterface $object) : void
47
    {
48
        static::ThrowIfNotType($object, $this->type, 1, __FUNCTION__);
49
50
        $id = [];
51
52
        foreach ($object::DaftObjectIdProperties() as $prop) {
53
            $id[] = $object->$prop;
54
        }
55
56
        $this->RemoveDaftObjectById($id);
57
    }
58
59
    public static function DaftObjectRepositoryByType(string $type) : DaftObjectRepository
60
    {
61
        foreach (
62
            [
63
                DaftObjectCreatedByArray::class,
64
                DefinesOwnIdPropertiesInterface::class,
65
            ] as $checkFor
66
        ) {
67
            static::ThrowIfNotType($type, $checkFor, 1, __FUNCTION__);
68
        }
69
70
        return new static($type);
71
    }
72
73
    public static function DaftObjectRepositoryByDaftObject(
74
        DefinesOwnIdPropertiesInterface $object
75
    ) : DaftObjectRepository {
76
        return static::DaftObjectRepositoryByType(get_class($object));
77
    }
78
79
    /**
80
    * @param DaftObject|string $object
81
    */
82
    protected static function ThrowIfNotType(
83
        $object,
84
        string $type,
85
        int $argument,
86
        string $function
87
    ) : void {
88
        if (false === is_a($object, $type, is_string($object))) {
89
            throw new DaftObjectRepositoryTypeByClassMethodAndTypeException(
90
                $argument,
91
                static::class,
92
                $function,
93
                $type,
94
                is_string($object) ? $object : get_class($object)
95
            );
96
        }
97
    }
98
}
99