RiesgoTabaco::numero()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
namespace src\riesgos;
3
4
use src\sustancias\Tabaco;
5
6
class RiesgoTabaco
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\Tabaco
31
     */
32
    private Tabaco $_tabaco;
33
34
    /**
35
     *
36
     * @param \src\sustancias\Tabaco $tabaco
37
     */
38 11
    public function __construct(Tabaco $tabaco)
39
    {
40 11
        $this->_tabaco = $tabaco;
41 11
    }
42
43
    /**
44
     *
45
     * @return string
46
     */
47 2
    public function numero(): string
48
    {
49
        return
50 2
        $this->_tabaco->preguntaDos()->numero() +
51 2
        $this->_tabaco->preguntaTres()->numero() +
52 2
        $this->_tabaco->preguntaCuatro()->numero() +
53 2
        $this->_tabaco->preguntaSeis()->numero() +
54 2
        $this->_tabaco->preguntaSiete()->numero();
55
    }
56
57
    /**
58
     *
59
     * @return string
60
     */
61 2
    public function texto(): string
62
    {
63 2
        return $this->setRiesgo($this->numero(), $this->_riesgo);
64
    }
65
66
    /**
67
     *
68
     * @return string
69
     */
70 2
    public function intervencion(): string
71
    {
72 2
        return $this->setRiesgo($this->numero(), $this->_intervencion);
73
    }
74
75
    /**
76
     *
77
     * @param string $riesgo
78
     * @param array $comparador
79
     *
80
     * @return string
81
     */
82 2
    private function setRiesgo(string $riesgo, array $comparador): string
83
    {
84 2
        foreach ($comparador as $key => $value) {
85 2
            $val = explode('-', $key);
86
            
87 2
            if ($riesgo >= $val[0] && $riesgo <= $val[1]) {
88 2
                $riesgo = $value;
89
            }
90
        }
91
92 2
        return $riesgo;
93
    }
94
}
95