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 Override;
0 ignored issues
show
Bug introduced by
The type Override 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...
8
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
9
use Stu\Orm\Entity\Ship;
10
use Stu\Orm\Entity\Spacecraft;
11
use Stu\Orm\Entity\User;
12
13
class SpacecraftGroup implements SpacecraftGroupInterface
14
{
15
    /** @var Collection<int, SpacecraftWrapperInterface> */
16
    private Collection $spacecraftWrappers;
17
18 8
    public function __construct(
19
        private String $name,
20
        private ?User $user
21
    ) {
22 8
        $this->spacecraftWrappers = new ArrayCollection();
23
    }
24
25 8
    #[Override]
26
    public function addSpacecraftWrapper(SpacecraftWrapperInterface $wrapper): void
27
    {
28 8
        $this->spacecraftWrappers->add($wrapper);
29
    }
30
31 8
    #[Override]
32
    public function getWrappers(): Collection
33
    {
34 8
        return $this->spacecraftWrappers;
35
    }
36
37 3
    #[Override]
38
    public function getName(): string
39
    {
40 3
        return $this->name;
41
    }
42
43 3
    #[Override]
44
    public function getUser(): ?User
45
    {
46 3
        return $this->user;
47
    }
48
49
    /** 
50
     * @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...
51
     * 
52
     * @return Collection<int, Spacecraft>
53
     */
54 8
    public static function sortSpacecraftCollection(Collection $spacecrafts): Collection
55
    {
56 8
        $spacecraftArray = $spacecrafts->toArray();
57
58 8
        usort(
59 8
            $spacecraftArray,
60 8
            function (Spacecraft $a, Spacecraft $b): int {
61 7
                $fleetA = $a instanceof Ship ? $a->getFleet() : null;
62 7
                $fleetB = $b instanceof Ship ? $b->getFleet() : null;
63
64 7
                $fleetASort = $fleetA !== null ? $fleetA->getSort() : 0;
65 7
                $fleetBSort = $fleetB !== null ? $fleetB->getSort() : 0;
66 7
                if ($fleetBSort === $fleetASort) {
67 7
                    $fleetAid = $fleetA !== null ? $fleetA->getId() : 0;
68 7
                    $fleetBid = $fleetB !== null ? $fleetB->getId() : 0;
69 7
                    if ($fleetBid === $fleetAid) {
70 7
                        $aIsFleetLeader = $a instanceof Ship && $a->isFleetLeader();
71 7
                        $bIsFleetLeader = $b instanceof Ship && $b->isFleetLeader();
72 7
                        if ($bIsFleetLeader === $aIsFleetLeader) {
73 7
                            $catA = $a->getRump()->getCategoryId();
74 7
                            $catB = $b->getRump()->getCategoryId();
75 7
                            if ($catB === $catA) {
76 7
                                $roleA = $a->getRump()->getRoleId();
77 7
                                $roleB = $b->getRump()->getRoleId();
78 7
                                if ($roleB === $roleA) {
79 7
                                    if ($b->getRumpId() === $a->getRumpId()) {
80 7
                                        return $a->getName() <=> $b->getName();
81
                                    }
82
83
                                    return $b->getRumpId() <=> $a->getRumpId();
84
                                }
85
86
                                return $roleB <=> $roleA;
87
                            }
88
                            return $catB <=> $catA;
89
                        }
90 1
                        return $bIsFleetLeader <=> $aIsFleetLeader;
91
                    }
92
                    return $fleetBid <=> $fleetAid;
93
                }
94 7
                return $fleetBSort <=> $fleetASort;
95 8
            }
96 8
        );
97
98 8
        return new ArrayCollection($spacecraftArray);
99
    }
100
}
101