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.

TraitSortableDaftObject   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A CompareToDaftSortableObject() 0 11 3
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 4
    public function CompareToDaftSortableObject(DaftSortableObject $otherObject) : int
25
    {
26 4
        foreach (static::DaftSortableObjectProperties() as $property) {
27 4
            $sort = $this->__get($property) <=> $otherObject->__get($property);
28
29 4
            if (0 !== $sort) {
30 4
                return $sort;
31
            }
32
        }
33
34 4
        return 0;
35
    }
36
37
    /**
38
    * @return array<int, string>
39
    */
40 16
    public static function DaftSortableObjectProperties() : array
41
    {
42 16
        if ( ! is_a(static::class, DaftSortableObject::class, true)) {
43 4
            throw Exceptions\Factory::ClassDoesNotImplementClassException(
44 4
                static::class,
45 4
                DaftSortableObject::class
46
            );
47
        }
48
49
        /**
50
        * @var array<int, string>
51
        */
52 12
        $out = constant(static::class . '::SORTABLE_PROPERTIES');
53
54 12
        return $out;
55
    }
56
}
57