Passed
Push — dev ( bd3e01...71c593 )
by Nico
07:03
created

TorpedoHull   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 46
dl 0
loc 149
ccs 0
cts 52
cp 0
rs 10
c 2
b 1
f 0
wmc 15

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A getTorpedoType() 0 3 1
A setTorpedoType() 0 5 1
A getModuleId() 0 3 1
A setModificator() 0 5 1
A setModuleId() 0 5 1
A getTorpedo() 0 3 1
A getModule() 0 3 1
A getModificator() 0 3 1
A calculateGradientColor() 0 17 1
A calculateGradientRgb() 0 7 1
A hexToRgb() 0 16 3
A rgbToHex() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Entity;
9
use Doctrine\ORM\Mapping\GeneratedValue;
10
use Doctrine\ORM\Mapping\Id;
11
use Doctrine\ORM\Mapping\JoinColumn;
12
use Doctrine\ORM\Mapping\ManyToOne;
13
use Doctrine\ORM\Mapping\Table;
14
15
/**
16
 * @Entity(repositoryClass="Stu\Orm\Repository\TorpedoHullRepository")
17
 * @Table(
18
 *     name="stu_torpedo_hull")
19
 **/
20
class TorpedoHull implements TorpedoHullInterface
21
{
22
    /**
23
     * @Id
24
     * @Column(type="integer")
25
     * @GeneratedValue(strategy="IDENTITY")
26
     *
27
     */
28
    private int $id;
29
30
    /**
31
     * @Column(type="integer")
32
     *
33
     */
34
    private int $module_id = 0;
35
36
    /**
37
     * @Column(type="integer")
38
     *
39
     */
40
    private int $torpedo_type = 0;
41
42
    /**
43
     * @Column(type="integer")
44
     *
45
     */
46
    private int $modificator = 0;
47
48
49
    /**
50
     * @var ?TorpedoType
51
     *
52
     * @ManyToOne(targetEntity="TorpedoType")
53
     * @JoinColumn(name="torpedo_type", referencedColumnName="id")
54
     */
55
    private $torpedo;
56
57
    /**
58
     * @var ?Module
59
     *
60
     * @ManyToOne(targetEntity="Module")
61
     * @JoinColumn(name="module_id", referencedColumnName="id")
62
     */
63
    private $module;
64
65
    public function getId(): int
66
    {
67
        return $this->id;
68
    }
69
70
    public function getModuleId(): int
71
    {
72
        return $this->module_id;
73
    }
74
75
    public function setModuleId(int $moduleId): TorpedoHullInterface
76
    {
77
        $this->module_id = $moduleId;
78
79
        return $this;
80
    }
81
82
    public function getTorpedoType(): int
83
    {
84
        return $this->torpedo_type;
85
    }
86
87
    public function setTorpedoType(int $torpedoType): TorpedoHullInterface
88
    {
89
        $this->torpedo_type = $torpedoType;
90
91
        return $this;
92
    }
93
94
    public function getModificator(): int
95
    {
96
        return $this->modificator;
97
    }
98
99
    public function setModificator(int $Modificator): TorpedoHullInterface
100
    {
101
        $this->modificator = $Modificator;
102
103
        return $this;
104
    }
105
106
    public function getTorpedo(): ?TorpedoTypeInterface
107
    {
108
        return $this->torpedo;
109
    }
110
111
    public function getModule(): ?ModuleInterface
112
    {
113
        return $this->module;
114
    }
115
116
    public function calculateGradientColor()
117
    {
118
        $color1 = '#00ff00';
119
        $color2 = '#FF0000';
120
        $percent = 100 / 29 * ($this->getModificator() - 88);
121
122
        // Konvertiere die Hex-Farbcodes in RGB-Werte
123
        $rgb1 = $this->hexToRgb($color1);
124
        $rgb2 = $this->hexToRgb($color2);
125
126
        // Berechne den RGB-Wert für den gegebenen Prozentwert
127
        $gradientRgb = $this->calculateGradientRgb($rgb1, $rgb2, $percent);
128
129
        // Konvertiere den RGB-Wert zurück in einen Hex-Farbcode
130
        $gradientColor = $this->rgbToHex($gradientRgb);
131
132
        return $gradientColor;
133
    }
134
135
    public function hexToRgb($color)
136
    {
137
        $color = ltrim($color, '#');
138
        $length = strlen($color);
139
140
        if ($length == 3) {
141
            $r = hexdec(substr($color, 0, 1) . substr($color, 0, 1));
142
            $g = hexdec(substr($color, 1, 1) . substr($color, 1, 1));
143
            $b = hexdec(substr($color, 2, 1) . substr($color, 2, 1));
144
        } elseif ($length == 6) {
145
            $r = hexdec(substr($color, 0, 2));
146
            $g = hexdec(substr($color, 2, 2));
147
            $b = hexdec(substr($color, 4, 2));
148
        }
149
150
        return array($r, $g, $b);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $g does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $r does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $b does not seem to be defined for all execution paths leading up to this point.
Loading history...
151
    }
152
153
    public function calculateGradientRgb($rgb1, $rgb2, $percent)
154
    {
155
        $r = intval($rgb1[0] + ($rgb2[0] - $rgb1[0]) * $percent / 100);
156
        $g = intval($rgb1[1] + ($rgb2[1] - $rgb1[1]) * $percent / 100);
157
        $b = intval($rgb1[2] + ($rgb2[2] - $rgb1[2]) * $percent / 100);
158
159
        return array($r, $g, $b);
160
    }
161
162
    public function rgbToHex($rgb)
163
    {
164
        $r = str_pad(dechex($rgb[0]), 2, '0', STR_PAD_LEFT);
165
        $g = str_pad(dechex($rgb[1]), 2, '0', STR_PAD_LEFT);
166
        $b = str_pad(dechex($rgb[2]), 2, '0', STR_PAD_LEFT);
167
168
        return '#' . $r . $g . $b;
169
    }
170
}