SpacecraftGroup   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 90.7%

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 86
ccs 39
cts 43
cp 0.907
rs 10
c 0
b 0
f 0
wmc 20

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A __construct() 0 5 1
A getWrappers() 0 4 1
C sortSpacecraftCollection() 0 45 15
A getUser() 0 4 1
A addSpacecraftWrapper() 0 4 1
1
<?php
2
3
namespace Stu\Module\Spacecraft\Lib;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
8
use Stu\Orm\Entity\Ship;
9
use Stu\Orm\Entity\Spacecraft;
10
use Stu\Orm\Entity\User;
11
12
class SpacecraftGroup implements SpacecraftGroupInterface
13
{
14
    /** @var Collection<int, SpacecraftWrapperInterface> */
15
    private Collection $spacecraftWrappers;
16
17 8
    public function __construct(
18
        private String $name,
19
        private ?User $user
20
    ) {
21 8
        $this->spacecraftWrappers = new ArrayCollection();
22
    }
23
24 8
    #[\Override]
25
    public function addSpacecraftWrapper(SpacecraftWrapperInterface $wrapper): void
26
    {
27 8
        $this->spacecraftWrappers->add($wrapper);
28
    }
29
30 8
    #[\Override]
31
    public function getWrappers(): Collection
32
    {
33 8
        return $this->spacecraftWrappers;
34
    }
35
36 3
    #[\Override]
37
    public function getName(): string
38
    {
39 3
        return $this->name;
40
    }
41
42 3
    #[\Override]
43
    public function getUser(): ?User
44
    {
45 3
        return $this->user;
46
    }
47
48
    /** 
49
     * @param Collection<int, covariant Spacecraft> $spacecrafts 
0 ignored issues
show
Bug introduced by
The type Stu\Module\Spacecraft\Lib\covariant was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
50
     * 
51
     * @return Collection<int, Spacecraft>
52
     */
53 8
    public static function sortSpacecraftCollection(Collection $spacecrafts): Collection
54
    {
55 8
        $spacecraftArray = $spacecrafts->toArray();
56
57 8
        usort(
58 8
            $spacecraftArray,
59 8
            function (Spacecraft $a, Spacecraft $b): int {
60 7
                $fleetA = $a instanceof Ship ? $a->getFleet() : null;
61 7
                $fleetB = $b instanceof Ship ? $b->getFleet() : null;
62
63 7
                $fleetASort = $fleetA !== null ? $fleetA->getSort() : 0;
64 7
                $fleetBSort = $fleetB !== null ? $fleetB->getSort() : 0;
65 7
                if ($fleetBSort === $fleetASort) {
66 7
                    $fleetAid = $fleetA !== null ? $fleetA->getId() : 0;
67 7
                    $fleetBid = $fleetB !== null ? $fleetB->getId() : 0;
68 7
                    if ($fleetBid === $fleetAid) {
69 7
                        $aIsFleetLeader = $a instanceof Ship && $a->isFleetLeader();
70 7
                        $bIsFleetLeader = $b instanceof Ship && $b->isFleetLeader();
71 7
                        if ($bIsFleetLeader === $aIsFleetLeader) {
72 7
                            $catA = $a->getRump()->getCategoryId();
73 7
                            $catB = $b->getRump()->getCategoryId();
74 7
                            if ($catB === $catA) {
75 7
                                $roleA = $a->getRump()->getRoleId();
76 7
                                $roleB = $b->getRump()->getRoleId();
77 7
                                if ($roleB === $roleA) {
78 7
                                    if ($b->getRumpId() === $a->getRumpId()) {
79 7
                                        return $a->getName() <=> $b->getName();
80
                                    }
81
82
                                    return $b->getRumpId() <=> $a->getRumpId();
83
                                }
84
85
                                return $roleB <=> $roleA;
86
                            }
87
                            return $catB <=> $catA;
88
                        }
89 1
                        return $bIsFleetLeader <=> $aIsFleetLeader;
90
                    }
91
                    return $fleetBid <=> $fleetAid;
92
                }
93 7
                return $fleetBSort <=> $fleetASort;
94 8
            }
95 8
        );
96
97 8
        return new ArrayCollection($spacecraftArray);
98
    }
99
}
100