Passed
Push — master ( 32373f...f18c17 )
by Benjamin
05:50 queued 01:43
created

TeamHelper   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 29.17%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 18
c 2
b 0
f 0
dl 0
loc 64
ccs 7
cts 24
cp 0.2917
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRuleHelper() 0 6 2
A __construct() 0 3 1
A createNewTeamVersion() 0 4 1
A destructTeamVersion() 0 2 1
A couldHaveApothecary() 0 6 2
A getLastVersion() 0 11 2
1
<?php
2
3
namespace Obblm\Core\Helper;
4
5
use Obblm\Core\Entity\Team;
6
use Obblm\Core\Entity\TeamVersion;
7
use Obblm\Core\Contracts\RuleHelperInterface;
8
9
/**
10
 * Class TeamHelper
11
 * @package Obblm\Core\Helper
12
 */
13
class TeamHelper
14
{
15
    private $ruleHelper;
16
17
    public function __construct(RuleHelper $ruleHelper)
18
    {
19
        $this->ruleHelper = $ruleHelper;
20
    }
21
22
    /**
23
     * @param Team $team
24
     * @return RuleHelperInterface
25
     * @throws \Exception
26
     */
27
    public function getRuleHelper(Team $team):RuleHelperInterface
28
    {
29
        if (!$team->getRule()) {
30
            throw new \Exception('This team does not have a rule');
31
        }
32
        return $this->ruleHelper->getHelper($team->getRule());
33
    }
34
35 1
    public static function getLastVersion(Team  $team):TeamVersion
36
    {
37 1
        $versions = $team->getVersions();
38
        /** @var TeamVersion $last */
39 1
        $last = $versions->first();
40 1
        if ($last) {
0 ignored issues
show
introduced by
$last is of type Obblm\Core\Entity\TeamVersion, thus it always evaluated to true.
Loading history...
41
            return $last;
42
        }
43 1
        $version = new TeamVersion();
44 1
        $team->addVersion($version);
45 1
        return $version;
46
    }
47
48
    /**********************
49
     * TEAM HELPER METHODS
50
     **********************/
51
52
    /**
53
     * @param Team $team
54
     * @return TeamVersion
55
     * @throws \Psr\Cache\InvalidArgumentException
56
     */
57
    public function createNewTeamVersion(Team $team):TeamVersion
58
    {
59
        return (TeamHelper::getLastVersion($team))
60
            ->setTreasure($this->ruleHelper->getHelper($team->getRule())->getMaxTeamCost());
61
    }
62
    public function destructTeamVersion(Team $team):TeamVersion
0 ignored issues
show
Unused Code introduced by
The parameter $team is not used and could be removed. ( Ignorable by Annotation )

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

62
    public function destructTeamVersion(/** @scrutinizer ignore-unused */ Team $team):TeamVersion

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Obblm\Core\Entity\TeamVersion. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
65
66
    /**
67
     * @param Team $team
68
     * @return bool
69
     * @throws \Exception
70
     */
71
    public function couldHaveApothecary(Team $team):bool
72
    {
73
        if (!$team->getRule()) {
74
            throw new \Exception('This team does not have a rule');
75
        }
76
        return (bool) $this->getRuleHelper($team)->couldHaveApothecary($team);
77
    }
78
}
79