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.
Passed
Branch object-only (2b4c07)
by SignpostMarv
14:54
created

TraitSortableDaftObject   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 16
dl 0
loc 48
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A CompareToDaftSortableObject() 0 18 4
A DaftSortableObjectProperties() 0 15 2
1
<?php
2
/**
3
* Exceptions.
4
*
5
* @author SignpostMarv
6
*/
7
declare(strict_types=1);
8
9
namespace SignpostMarv\DaftObject;
10
11
/**
12
* @template T as DaftSortableObject
13
*/
14
trait TraitSortableDaftObject
15
{
16
    /**
17
    * @return scalar|array|object|null
18
    */
19
    abstract public function __get(string $property);
20
21
    /**
22
    * @psalm-param T as $otherObject
23
    */
24
    public function CompareToDaftSortableObject(DaftSortableObject $otherObject) : int
25
    {
26
        if ( ! is_a(static::class, DaftSortableObject::class, true)) {
27
            throw new ClassDoesNotImplementClassException(
28
                static::class,
29
                DaftSortableObject::class
30
            );
31
        }
32
33
        foreach (static::DaftSortableObjectProperties() as $property) {
34
            $sort = $this->__get($property) <=> $otherObject->__get($property);
35
36
            if (0 !== $sort) {
37
                return $sort;
38
            }
39
        }
40
41
        return 0;
42
    }
43
44
    /**
45
    * @return array<int, string>
46
    */
47
    public static function DaftSortableObjectProperties() : array
48
    {
49
        if ( ! is_a(static::class, DaftSortableObject::class, true)) {
50
            throw new ClassDoesNotImplementClassException(
51
                static::class,
52
                DaftSortableObject::class
53
            );
54
        }
55
56
        /**
57
        * @var array<int, string>
58
        */
59
        $out = (array) constant(static::class . '::SORTABLE_PROPERTIES');
60
61
        return $out;
62
    }
63
}
64