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

pregunta8()   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 RecuerdosPersistentesSobreElAcontecimiento
8
{
9
    private $_acontecimientoTraumaticoSevero;
10
    private $_pregunta7;
11
    private $_pregunta8;
12
    
13
    public function __construct
14
    (
15
        AcontecimientoTraumaticoSevero $AcontecimientoTraumaticoSevero,
16
        string $pregunta7,
17
        string $pregunta8
18
    )
19
    {
20
        $this->_acontecimientoTraumaticoSevero = $AcontecimientoTraumaticoSevero;
21
        $this->_pregunta7 = $this->setPregunta($pregunta7);
22
        $this->_pregunta8 = $this->setPregunta($pregunta8);
23
    }
24
25
    public function pregunta7(): string
26
    {
27
        return $this->_pregunta7;
28
    }
29
30
    public function pregunta8(): string
31
    {
32
        return $this->_pregunta8;
33
    }
34
35
    private function setPregunta(string $respuesta): string
36
    {
37
        if($this->existeRespuestaPositivaEnETS())
38
        {
39
            if($this->verificarRespuesta($respuesta))
40
            {
41
                return $respuesta;
42
            }
43
        }
44
        else
45
        {
46
            return 'No';
47
        }
48
49
        throw new Exception("Error procesando respuesta", 1);
50
        
51
    }
52
53
    private function verificarRespuesta(string $respuesta): bool
54
    {
55
        if($respuesta == 'Sí' || $respuesta == 'No')
56
        {
57
            return true;
58
        }
59
60
        return false;
61
    }
62
63
    /*
64
    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 
65
    */
66
    private function existeRespuestaPositivaEnETS(): bool
67
    {
68
        $respuestasETS = array(
69
            'pregunta1',
70
            'pregunta2',
71
            'pregunta3',
72
            'pregunta4',
73
            'pregunta5',
74
            'pregunta6'
75
        );
76
        
77
        foreach($respuestasETS as $respuesta)
78
        {
79
            if($this->_acontecimientoTraumaticoSevero->{$respuesta}() == 'Sí')
80
            {
81
                return true;
82
            }
83
        }
84
        
85
        return false;
86
    }
87
}