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 ( ce1e69...5665d5 )
by SignpostMarv
04:49
created

AbstractDaftObjectRepository   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 45.65 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 42
loc 92
ccs 43
cts 43
cp 1
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A DaftObjectRepositoryByDaftObject() 0 4 1
A ForgetDaftObject() 20 20 3
A DaftObjectRepositoryByType() 0 20 2
A RemoveDaftObject() 20 20 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    * mixed[][].
20
    */
21
    protected $data = [];
22
23
    /**
24
    * @var string
25
    */
26
    protected $type;
27
28 6
    protected function __construct(string $type)
29
    {
30 6
        $this->type = $type;
31 6
    }
32
33 3 View Code Duplication
    public function ForgetDaftObject(
34
        DefinesOwnIdPropertiesInterface $object
35
    ) : void {
36 3
        if (false === is_a($object, $this->type, true)) {
37 1
            throw new DaftObjectRepositoryTypeByClassMethodAndTypeException(
38 1
                1,
39 1
                static::class,
40 1
                __FUNCTION__,
41 1
                $this->type,
42 1
                get_class($object)
43
            );
44
        }
45
46 2
        $id = [];
47
48 2
        foreach ($object::DaftObjectIdProperties() as $prop) {
49 2
            $id[] = $object->$prop;
50
        }
51
52 2
        $this->ForgetDaftObjectById($id);
53 2
    }
54
55 3 View Code Duplication
    public function RemoveDaftObject(
56
        DefinesOwnIdPropertiesInterface $object
57
    ) : void {
58 3
        if (false === is_a($object, $this->type, true)) {
59 1
            throw new DaftObjectRepositoryTypeByClassMethodAndTypeException(
60 1
                1,
61 1
                static::class,
62 1
                __FUNCTION__,
63 1
                $this->type,
64 1
                get_class($object)
65
            );
66
        }
67
68 2
        $id = [];
69
70 2
        foreach ($object::DaftObjectIdProperties() as $prop) {
71 2
            $id[] = $object->$prop;
72
        }
73
74 2
        $this->RemoveDaftObjectById($id);
75 2
    }
76
77 6
    public static function DaftObjectRepositoryByType(
78
        string $type
79
    ) : DaftObjectRepository {
80
        if (
81 6
            false === is_a(
82 6
                $type,
83 6
                DefinesOwnIdPropertiesInterface::class,
84 6
                true
85
            )
86
        ) {
87 1
            throw new DaftObjectRepositoryTypeByClassMethodAndTypeException(
88 1
                1,
89 1
                static::class,
90 1
                __FUNCTION__,
91 1
                DefinesOwnIdPropertiesInterface::class,
92 1
                $type
93
            );
94
        }
95
96 6
        return new static($type);
97
    }
98
99 5
    public static function DaftObjectRepositoryByDaftObject(
100
        DefinesOwnIdPropertiesInterface $object
101
    ) : DaftObjectRepository {
102 5
        return static::DaftObjectRepositoryByType(get_class($object));
103
    }
104
}
105