Passed
Push — main ( cd0525...18fc2b )
by Osvaldo
01:28
created

Afectacion::pregunta20()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace src;
3
4
use Exception;
5
use src\AcontecimientoTraumaticoSevero;
6
7
class Afectacion
8
{
9
    private $_acontecimientoTraumaticoSevero;
10
    private $_pregunta16;
11
    private $_pregunta17;
12
    private $_pregunta18;
13
    private $_pregunta19;
14
    private $_pregunta20;
15
   
16
    public function __construct
17
    (
18
        AcontecimientoTraumaticoSevero $AcontecimientoTraumaticoSevero,
19
        string $pregunta16,
20
        string $pregunta17,
21
        string $pregunta18,
22
        string $pregunta19,
23
        string $pregunta20
24
    )
25
    {
26
        $this->_acontecimientoTraumaticoSevero = $AcontecimientoTraumaticoSevero;
27
        $this->_pregunta16 = $this->setPregunta($pregunta16);
28
        $this->_pregunta17 = $this->setPregunta($pregunta17);
29
        $this->_pregunta18 = $this->setPregunta($pregunta18);
30
        $this->_pregunta19 = $this->setPregunta($pregunta19);
31
        $this->_pregunta20 = $this->setPregunta($pregunta20);
32
    }
33
34
    public function pregunta16(): string
35
    {
36
        return $this->_pregunta16;
37
    }
38
39
    public function pregunta17(): string
40
    {
41
        return $this->_pregunta17;
42
    }
43
44
    public function pregunta18(): string
45
    {
46
        return $this->_pregunta18;
47
    }
48
49
    public function pregunta19(): string
50
    {
51
        return $this->_pregunta19;
52
    }
53
54
    public function pregunta20(): string
55
    {
56
        return $this->_pregunta20;
57
    }
58
59
    private function setPregunta(string $respuesta): string
60
    {
61
        if($this->existeRespuestaPositivaEnETS())
62
        {
63
            if($this->verificarRespuesta($respuesta))
64
            {
65
                return $respuesta;
66
            }
67
        }
68
        else
69
        {
70
            return 'No';
71
        }
72
73
        throw new Exception("Error procesando respuesta", 1);
74
        
75
    }
76
77
    private function verificarRespuesta(string $respuesta): bool
78
    {
79
        
80
        if($respuesta == 'Sí' || $respuesta == 'No')
81
        {
82
            return true;
83
        }
84
85
        return false;
86
    }
87
88
    /*
89
    Prevenir que si en la primer sección del cuestionario de ATS se responde con No a todo se pueda almacenar un sí en otros 
90
    */
91
    private function existeRespuestaPositivaEnETS(): bool
92
    {
93
        $respuestasETS = array(
94
            'pregunta1',
95
            'pregunta2',
96
            'pregunta3',
97
            'pregunta4',
98
            'pregunta5',
99
            'pregunta6'
100
        );
101
        
102
        foreach($respuestasETS as $respuesta)
103
        {
104
            if($this->_acontecimientoTraumaticoSevero->{$respuesta}() == 'Sí')
105
            {
106
                return true;
107
            }
108
        }
109
        
110
        return false;
111
    }
112
}