Passed
Pull Request — master (#1969)
by Janko
22:34 queued 10:03
created

AcademyProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
dl 0
loc 59
ccs 32
cts 36
cp 0.8889
rs 10
c 1
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
B setTemplateVariables() 0 54 6
1
<?php
2
3
namespace Stu\Module\Colony\Lib\Gui\Component;
4
5
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...
6
use Stu\Component\Crew\CrewCountRetrieverInterface;
7
use Stu\Lib\Colony\PlanetFieldHostInterface;
8
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Orm\Entity\ColonyInterface;
11
12
final class AcademyProvider implements PlanetFieldHostComponentInterface
13
{
14 1
    public function __construct(private ColonyLibFactoryInterface $colonyLibFactory, private CrewCountRetrieverInterface $crewCountRetriever) {}
15
16
    /** @param ColonyInterface&PlanetFieldHostInterface $entity */
17 1
    #[Override]
18
    public function setTemplateVariables(
19
        $entity,
20
        GameControllerInterface $game
21
    ): void {
22 1
        $user = $game->getUser();
23
24 1
        $crewInTrainingCount = $this->crewCountRetriever->getInTrainingCount($user);
25 1
        $crewRemainingCount = $this->crewCountRetriever->getRemainingCount($user);
26 1
        $crewTrainableCount = $this->crewCountRetriever->getTrainableCount($user);
27
28 1
        $trainableCrew = $crewTrainableCount - $crewInTrainingCount;
29 1
        if ($trainableCrew > $crewRemainingCount) {
30 1
            $trainableCrew = $crewRemainingCount;
31
        }
32
33 1
        if ($trainableCrew > $entity->getWorkless()) {
34
            $trainableCrew = $entity->getWorkless();
35
        }
36
37 1
        $freeAssignmentCount = $this->colonyLibFactory->createColonyPopulationCalculator(
38 1
            $entity
39 1
        )->getFreeAssignmentCount();
40
41 1
        $localcrewlimit = $this->colonyLibFactory->createColonyPopulationCalculator(
42 1
            $entity
43 1
        )->getCrewLimit();
44
45 1
        $crewinlocalpool = $entity->getCrewAssignmentAmount();
46
47 1
        if ($localcrewlimit - $crewinlocalpool < $trainableCrew) {
48
            $trainableCrew = $localcrewlimit - $crewinlocalpool;
49
        }
50
51 1
        if ($trainableCrew > $freeAssignmentCount) {
52
            $trainableCrew = $freeAssignmentCount;
53
        }
54
55 1
        if ($trainableCrew < 0) {
56
            $trainableCrew = 0;
57
        }
58
59 1
        $game->setTemplateVar('TRAINABLE_CREW_COUNT_PER_TICK', $trainableCrew);
60 1
        $game->setTemplateVar(
61 1
            'CREW_COUNT_TRAINING',
62 1
            $crewInTrainingCount
63 1
        );
64 1
        $game->setTemplateVar(
65 1
            'CREW_COUNT_REMAINING',
66 1
            $crewRemainingCount
67 1
        );
68 1
        $game->setTemplateVar(
69 1
            'CREW_COUNT_TRAINABLE',
70 1
            $crewTrainableCount
71 1
        );
72
    }
73
}
74