Player   A
last analyzed

Complexity

Total Complexity 29

Size/Duplication

Total Lines 118
Duplicated Lines 27.12 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 0 Features 4
Metric Value
wmc 29
c 7
b 0
f 4
lcom 1
cbo 1
dl 32
loc 118
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 9 9 1
A calculateVal() 0 12 2
A getWage() 11 11 3
A getVal() 0 7 2
B priceOnSkill() 12 12 8
B onAgeModifier() 0 10 7
B onRoleModifier() 0 17 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}