Player::onRoleModifier()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 17
rs 8.8571
cc 6
eloc 13
nc 6
nop 0
1
<?php
2
3
namespace App\Lib\DsManager\Models;
4
5
use App\Lib\DsManager\Models\Common\Person;
6
7
/**
8
 * Class Player
9
 * @package App\Lib\DsManager\Models
10
 */
11
class Player extends Person
12
{
13
	/**
14
	 * @var
15
	 */
16
	public $role;
17
18
	/**
19
	 * @var
20
	 */
21
	public $val;
22
23
	/**
24
	 * @return array
25
	 */
26 View Code Duplication
	public function toArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
	{
28
		$result = parent::toArray();
29
		$result["role"] = $this->role;
30
		$result['val'] = $this->getVal();
31
		$result['wageReq'] = $this->getWage();
32
33
		return $result;
34
	}
35
36
	/**
37
	 * @return float|int
38
	 */
39
	private function calculateVal()
40
	{
41
		$val = $this->priceOnSkill();
42
		$val = $val * (1 + $this->onAgeModifier());
43
		$val += rand(1, 3);
44
		$val -= rand(1, 3);
45
		$val += $this->onRoleModifier();
46
		$val += $this->spareChange();
47
		if ($val < 0) $val = $val * -1;
48
		$val = round($val, 2);
49
		return $val;
50
	}
51
52
	/**
53
	 * @return float|int
54
	 */
55 View Code Duplication
	public function getWage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
	{
57
		if ($this->wageReq == null) {
58
			$wage = round($this->getVal() / 10.0, 2);
59
			$wage += $this->spareChange();
60
			if ($wage < 0) $wage = $wage * -1;
61
			$this->wageReq = round($wage, 2);
62
		}
63
		return $this->wageReq;
64
65
	}
66
67
	/**
68
	 * @return float|int
69
	 */
70
	public function getVal()
71
	{
72
		if ($this->val === null) {
73
			$this->val = $this->calculateVal();
74
		}
75
		return $this->val;
76
	}
77
78
	/**
79
	 * @return float
80
	 */
81 View Code Duplication
	private function priceOnSkill()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
	{
83
		if ($this->skillAvg > 98) return 130.0;
84
		if ($this->skillAvg > 90) return 80.0;
85
		if ($this->skillAvg > 80) return 50.0;
86
		if ($this->skillAvg > 76) return 20.0;
87
		if ($this->skillAvg > 70) return 10.0;
88
		if ($this->skillAvg > 60) return 5.0;
89
		if ($this->skillAvg > 50) return 2.0;
90
		return 0.5;
91
92
	}
93
94
	/**
95
	 * @return float
96
	 */
97
	private function onAgeModifier()
98
	{
99
		if ($this->age > 32) return -0.5;
100
		if ($this->age > 30) return -0.2;
101
		if ($this->age > 28) return -0.1;
102
		if ($this->age > 26) return 0.1;
103
		if ($this->age > 22) return 0.2;
104
		if ($this->age > 20) return 0.3;
105
		return 0.5;
106
	}
107
108
	/**
109
	 * @return int
110
	 */
111
	private function onRoleModifier()
112
	{
113
		$result = 0;
114
		if ($this->role == "CS") {
115
			$result += rand(0, 4);
116
		} else if ($this->role == "LS") {
117
			$result += rand(0, 2);
118
		} else if ($this->role == "RS") {
119
			$result += rand(0, 2);
120
		} else if ($this->role == "CM") {
121
			$result += rand(0, 3);
122
		} else if ($this->role == "CD") {
123
			$result += rand(0, 2);
124
		}
125
126
		return $result;
127
	}
128
}