RiesgoCocaina::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
namespace src\riesgos;
3
4
use src\sustancias\Cocaina;
5
6
class RiesgoCocaina
7
{
8
    /**
9
     *
10
     * @var array
11
     */
12
    private array $_intervencion = [
13
        '0-3' => 'No requiere intervención (consejo breve)',
14
        '4-26' => 'Requiere intervención breve',
15
        '27-99' => 'Requiere tratamiento más intensivo'
16
    ];
17
18
    /**
19
     *
20
     * @var array
21
     */
22
    private array $_riesgo = [
23
        '0-3' => 'Riesgo bajo',
24
        '4-26' => 'Riesgo moderado',
25
        '27-99' => 'Riesgo alto'
26
    ];
27
28
    /**
29
     *
30
     * @var \src\sustancias\Cocaina
31
     */
32
    private Cocaina $_cocaina;
33
34
    /**
35
     *
36
     * @param \src\sustancias\Cocaina $Cocaina
37
     */
38 11
    public function __construct(Cocaina $Cocaina)
39
    {
40 11
        $this->_cocaina = $Cocaina;
41 11
    }
42
43
    /**
44
     *
45
     * @return string
46
     */
47 2
    public function numero(): string
48
    {
49
        return
50 2
        $this->_cocaina->preguntaDos()->numero() +
51 2
        $this->_cocaina->preguntaTres()->numero() +
52 2
        $this->_cocaina->preguntaCuatro()->numero() +
53 2
        $this->_cocaina->preguntaCinco()->numero() +
54 2
        $this->_cocaina->preguntaSeis()->numero() +
55 2
        $this->_cocaina->preguntaSiete()->numero();
56
    }
57
58
    /**
59
     *
60
     * @return string
61
     */
62 2
    public function texto(): string
63
    {
64 2
        return $this->setRiesgo($this->numero(), $this->_riesgo);
65
    }
66
67
    /**
68
     *
69
     * @return string
70
     */
71 2
    public function intervencion(): string
72
    {
73 2
        return $this->setRiesgo($this->numero(), $this->_intervencion);
74
    }
75
76
    /**
77
     *
78
     * @param string $riesgo
79
     * @param array $comparador
80
     *
81
     * @return string
82
     */
83 2
    private function setRiesgo(string $riesgo, array $comparador): string
84
    {
85 2
        foreach ($comparador as $key => $value) {
86 2
            $val = explode('-', $key);
87
            
88 2
            if ($riesgo >= $val[0] && $riesgo <= $val[1]) {
89 2
                $riesgo = $value;
90
            }
91
        }
92
93 2
        return $riesgo;
94
    }
95
}
96