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

AcademyProvider::setTemplateVariables()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 54
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 6.0537

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 33
nc 32
nop 2
dl 0
loc 54
ccs 31
cts 35
cp 0.8857
crap 6.0537
rs 8.7697
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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