Riesgos::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 10
dl 0
loc 22
ccs 11
cts 11
cp 1
crap 1
rs 9.9332

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 declare(strict_types=1);
2
namespace src\riesgos;
3
4
class Riesgos
5
{
6
    private RiesgoTabaco $_tabaco;
7
8
    private RiesgoAlcohol $_alcohol;
9
10
    private RiesgoCannabis $_cannabis;
11
12
    private RiesgoCocaina $_cocaina;
13
14
    private RiesgoAnfetamina $_anfetamina;
15
16
    private RiesgoInhalables $_inhalables;
17
18
    private RiesgoSedantes $_sedantes;
19
20
    private RiesgoAlucinogenos $_alucinogenos;
21
22
    private RiesgoOpiaceos $_opiaceos;
23
24
    private RiesgoOtros $_otros;
25
26 11
    public function __construct(
27
        RiesgoTabaco $riesgoTabaco,
28
        RiesgoAlcohol $riesgoAlcohol,
29
        RiesgoCannabis $riesgoCannabis,
30
        RiesgoCocaina $riesgoCocaina,
31
        RiesgoAnfetamina $riesgoAnfetamina,
32
        RiesgoInhalables $riesgoInhalables,
33
        RiesgoSedantes $riesgoSedantes,
34
        RiesgoAlucinogenos $riesgoAlucinogenos,
35
        RiesgoOpiaceos $riesgoOpiaceos,
36
        RiesgoOtros $riesgoOtros
37
    ) {
38 11
        $this->_tabaco = $riesgoTabaco;
39 11
        $this->_alcohol = $riesgoAlcohol;
40 11
        $this->_cannabis = $riesgoCannabis;
41 11
        $this->_cocaina = $riesgoCocaina;
42 11
        $this->_anfetamina = $riesgoAnfetamina;
43 11
        $this->_inhalables = $riesgoInhalables;
44 11
        $this->_sedantes = $riesgoSedantes;
45 11
        $this->_alucinogenos = $riesgoAlucinogenos;
46 11
        $this->_opiaceos = $riesgoOpiaceos;
47 11
        $this->_otros = $riesgoOtros;
48 11
    }
49
50 2
    public function tabaco(): RiesgoTabaco
51
    {
52 2
        return $this->_tabaco;
53
    }
54
    
55 2
    public function alcohol(): RiesgoAlcohol
56
    {
57 2
        return $this->_alcohol;
58
    }
59
60 2
    public function cannabis(): RiesgoCannabis
61
    {
62 2
        return $this->_cannabis;
63
    }
64
65 2
    public function cocaina(): RiesgoCocaina
66
    {
67 2
        return $this->_cocaina;
68
    }
69
70 2
    public function anfetamina(): RiesgoAnfetamina
71
    {
72 2
        return $this->_anfetamina;
73
    }
74
75 2
    public function inhalables(): RiesgoInhalables
76
    {
77 2
        return $this->_inhalables;
78
    }
79
80 2
    public function sedantes(): RiesgoSedantes
81
    {
82 2
        return $this->_sedantes;
83
    }
84
85 2
    public function alucinogenos(): RiesgoAlucinogenos
86
    {
87 2
        return $this->_alucinogenos;
88
    }
89
90 2
    public function opiaceos(): RiesgoOpiaceos
91
    {
92 2
        return $this->_opiaceos;
93
    }
94
95 2
    public function otros(): RiesgoOtros
96
    {
97 2
        return $this->_otros;
98
    }
99
}
100