Passed
Pull Request — master (#1696)
by Nico
49:43 queued 22:34
created

AcademyProvider::setTemplateVariables()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 41
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 26
nc 16
nop 2
dl 0
loc 41
ccs 0
cts 29
cp 0
crap 30
rs 9.1928
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Colony\Lib\Gui\Component;
4
5
use Stu\Component\Crew\CrewCountRetrieverInterface;
6
use Stu\Lib\Colony\PlanetFieldHostInterface;
7
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface;
8
use Stu\Module\Control\GameControllerInterface;
9
use Stu\Orm\Entity\ColonyInterface;
10
11
final class AcademyProvider implements GuiComponentProviderInterface
12
{
13
    private CrewCountRetrieverInterface $crewCountRetriever;
14
15
    private ColonyLibFactoryInterface $colonyLibFactory;
16
17
    public function __construct(
18
        ColonyLibFactoryInterface $colonyLibFactory,
19
        CrewCountRetrieverInterface $crewCountRetriever
20
    ) {
21
        $this->crewCountRetriever = $crewCountRetriever;
22
        $this->colonyLibFactory = $colonyLibFactory;
23
    }
24
25
    /** @param ColonyInterface&PlanetFieldHostInterface $host */
26
    public function setTemplateVariables(
27
        PlanetFieldHostInterface $host,
28
        GameControllerInterface $game
29
    ): void {
30
        $user = $game->getUser();
31
32
        $crewInTrainingCount = $this->crewCountRetriever->getInTrainingCount($user);
33
        $crewRemainingCount = $this->crewCountRetriever->getRemainingCount($user);
34
        $crewTrainableCount = $this->crewCountRetriever->getTrainableCount($user);
35
36
        $trainableCrew = $crewTrainableCount - $crewInTrainingCount;
37
        if ($trainableCrew > $crewRemainingCount) {
38
            $trainableCrew = $crewRemainingCount;
39
        }
40
        if ($trainableCrew < 0) {
41
            $trainableCrew = 0;
42
        }
43
        if ($trainableCrew > $host->getWorkless()) {
0 ignored issues
show
Bug introduced by
The method getWorkless() does not exist on Stu\Lib\Colony\PlanetFieldHostInterface. Did you maybe mean getWorkers()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        if ($trainableCrew > $host->/** @scrutinizer ignore-call */ getWorkless()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
            $trainableCrew = $host->getWorkless();
45
        }
46
47
        $freeAssignmentCount = $this->colonyLibFactory->createColonyPopulationCalculator(
48
            $host
49
        )->getFreeAssignmentCount();
50
51
        if ($trainableCrew > $freeAssignmentCount) {
52
            $trainableCrew = $freeAssignmentCount;
53
        }
54
55
        $game->setTemplateVar('TRAINABLE_CREW_COUNT_PER_TICK', $trainableCrew);
56
        $game->setTemplateVar(
57
            'CREW_COUNT_TRAINING',
58
            $crewInTrainingCount
59
        );
60
        $game->setTemplateVar(
61
            'CREW_COUNT_REMAINING',
62
            $crewRemainingCount
63
        );
64
        $game->setTemplateVar(
65
            'CREW_COUNT_TRAINABLE',
66
            $crewTrainableCount
67
        );
68
    }
69
}
70