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

__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 20
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace src;
3
4
use Exception;
5
use src\AcontecimientoTraumaticoSevero;
6
7
class EsfuerzoPorEvitarCircunstanciasParecidasOAsociadasAlAcontecimiento
8
{
9
    private $_acontecimientoTraumaticoSevero;
10
    private $_pregunta9;
11
    private $_pregunta10;
12
    private $_pregunta11;
13
    private $_pregunta12;
14
    private $_pregunta13;
15
    private $_pregunta14;
16
    private $_pregunta15;
17
18
    public function __construct
19
    (
20
        AcontecimientoTraumaticoSevero $AcontecimientoTraumaticoSevero,
21
        string $pregunta9,
22
        string $pregunta10,
23
        string $pregunta11,
24
        string $pregunta12,
25
        string $pregunta13,
26
        string $pregunta14,
27
        string $pregunta15
28
    )
29
    {
30
        $this->_acontecimientoTraumaticoSevero = $AcontecimientoTraumaticoSevero;
31
        $this->_pregunta9 = $this->setPregunta($pregunta9);
32
        $this->_pregunta10 = $this->setPregunta($pregunta10);
33
        $this->_pregunta11 = $this->setPregunta($pregunta11);
34
        $this->_pregunta12 = $this->setPregunta($pregunta12);
35
        $this->_pregunta13 = $this->setPregunta($pregunta13);
36
        $this->_pregunta14 = $this->setPregunta($pregunta14);
37
        $this->_pregunta15 = $this->setPregunta($pregunta15);
38
    }
39
40
    public function pregunta9(): string
41
    {
42
        return $this->_pregunta9;
43
    }
44
45
    public function pregunta10(): string
46
    {
47
        return $this->_pregunta10;
48
    }
49
50
    public function pregunta11(): string
51
    {
52
        return $this->_pregunta11;
53
    }
54
55
    public function pregunta12(): string
56
    {
57
        return $this->_pregunta12;
58
    }
59
60
    public function pregunta13(): string
61
    {
62
        return $this->_pregunta13;
63
    }
64
65
    public function pregunta14(): string
66
    {
67
        return $this->_pregunta14;
68
    }
69
70
    public function pregunta15(): string
71
    {
72
        return $this->_pregunta15;
73
    }
74
75
    private function setPregunta(string $respuesta): string
76
    {
77
        if($this->existeRespuestaPositivaEnETS())
78
        {
79
            if($this->verificarRespuesta($respuesta))
80
            {
81
                return $respuesta;
82
            }
83
        }
84
        else
85
        {
86
            return 'No';
87
        }
88
89
        throw new Exception("Error procesando respuesta", 1);
90
        
91
    }
92
93
    private function verificarRespuesta(string $respuesta): bool
94
    {
95
        if($respuesta == 'Sí' || $respuesta == 'No')
96
        {
97
            return true;
98
        }
99
100
        return false;
101
    }
102
103
    /*
104
    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 
105
    */
106
    private function existeRespuestaPositivaEnETS(): bool
107
    {
108
        $respuestasETS = array(
109
            'pregunta1',
110
            'pregunta2',
111
            'pregunta3',
112
            'pregunta4',
113
            'pregunta5',
114
            'pregunta6'
115
        );
116
        
117
        foreach($respuestasETS as $respuesta)
118
        {
119
            if($this->_acontecimientoTraumaticoSevero->{$respuesta}() == 'Sí')
120
            {
121
                return true;
122
            }
123
        }
124
        
125
        return false;
126
    }
127
}