Module::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 3
Metric Value
c 4
b 0
f 3
dl 0
loc 6
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace App\Lib\DsManager\Models;
4
5
6
/**
7
 * Class Module
8
 * @package App\Lib\DsManager\Models
9
 */
10
use App\Lib\Helpers\Config;
11
12
/**
13
 * Class Module
14
 * @package App\Lib\DsManager\Models
15
 */
16
class Module
17
{
18
	/**
19
	 * @var
20
	 */
21
	private $moduleCode;
22
	/**
23
	 * @var
24
	 */
25
	private $configuration;
26
27
	/**
28
	 * @param $module
29
	 */
30
	public function __construct($module)
31
	{
32
		$this->moduleCode = $module;
33
		$this->configuration = Config::get("modules.modules")[$module];
34
		if ($this->configuration == null) throw new \InvalidArgumentException("Not a valid Module supplied");
35
	}
36
37
	/**
38
	 *
39
	 */
40
	public function isOffensive()
41
	{
42
		return ($this->configuration["character"] === 1);
43
	}
44
45
	/**
46
	 *
47
	 */
48
	public function isBalanced()
49
	{
50
		return ($this->configuration["character"] === 2);
51
	}
52
53
	/**
54
	 *
55
	 */
56
	public function isDefensive()
57
	{
58
		return ($this->configuration["character"] === 4);
59
	}
60
61
	/**
62
	 * @return string
63
	 */
64
	function __toString()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
65
	{
66
		return "" . $this->moduleCode;
67
	}
68
69
70
	/**
71
	 * @param Team $team
72
	 * @return bool
73
	 */
74
	public function isApplicableToTeam(Team $team)
75
	{
76
		return $this->isApplicableToArray($team->playersPerRoleArray());
77
	}
78
79
	public function isApplicableToArray($playersForRole)
80
	{
81
		$roles = $this->getRoleNeeded();
82
		foreach ($roles as $role => $numbP) {
83
			if (!(isset($playersForRole[$role]) && $playersForRole[$role] >= $numbP)) {
84
				return false;
85
			}
86
		}
87
		return true;
88
	}
89
90
91
	/**
92
	 * @param bool $complete
93
	 * @return array
94
	 */
95
	public function getRoleNeeded($complete = false)
96
	{
97
		$rolesNeeded = [];
98
		$roles = \App\Lib\Helpers\Config::get('modules.roles');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $roles is correct as \App\Lib\Helpers\Config::get('modules.roles') (which targets App\Lib\Helpers\Config::get()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
99
		$rolesKeys = array_keys($roles);
100
		foreach ($this->configuration["roles"] as $index => $playNum) {
101
			if ($playNum != 0 || $complete)
102
				$rolesNeeded[$rolesKeys[$index]] = $playNum;
103
		}
104
105
		return $rolesNeeded;
106
	}
107
108
109
}