Sustancias::__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\sustancias;
3
4
class Sustancias
5
{
6
    private Tabaco $_tabaco;
7
8
    private Alcohol $_alcohol;
9
10
    private Cannabis $_cannabis;
11
12
    private Cocaina $_cocaina;
13
14
    private Anfetamina $_anfetamina;
15
16
    private Inhalables $_inhalables;
17
18
    private Sedantes $_sedantes;
19
20
    private Alucinogenos $_alucinogenos;
21
22
    private Opiaceos $_opiaceos;
23
24
    private Otros $_otros;
25
26 11
    public function __construct(
27
        Tabaco $tabaco,
28
        Alcohol $alcohol,
29
        Cannabis $cannabis,
30
        Cocaina $cocaina,
31
        Anfetamina $anfetamina,
32
        Inhalables $inhalables,
33
        Sedantes $sedantes,
34
        Alucinogenos $alucinogenos,
35
        Opiaceos $opiaceos,
36
        Otros $otros
37
    ) {
38 11
        $this->_tabaco = $tabaco;
39 11
        $this->_alcohol = $alcohol;
40 11
        $this->_cannabis = $cannabis;
41 11
        $this->_cocaina = $cocaina;
42 11
        $this->_anfetamina = $anfetamina;
43 11
        $this->_inhalables = $inhalables;
44 11
        $this->_sedantes = $sedantes;
45 11
        $this->_alucinogenos = $alucinogenos;
46 11
        $this->_opiaceos = $opiaceos;
47 11
        $this->_otros = $otros;
48 11
    }
49
50 11
    public function tabaco(): Tabaco
51
    {
52 11
        return $this->_tabaco;
53
    }
54
55 11
    public function alcohol(): Alcohol
56
    {
57 11
        return $this->_alcohol;
58
    }
59
60 11
    public function cannabis(): Cannabis
61
    {
62 11
        return $this->_cannabis;
63
    }
64
65 11
    public function cocaina(): Cocaina
66
    {
67 11
        return $this->_cocaina;
68
    }
69
70 11
    public function anfetamina(): Anfetamina
71
    {
72 11
        return $this->_anfetamina;
73
    }
74
75 11
    public function inhalables(): Inhalables
76
    {
77 11
        return $this->_inhalables;
78
    }
79
80 11
    public function sedantes(): Sedantes
81
    {
82 11
        return $this->_sedantes;
83
    }
84
85 11
    public function alucinogenos(): Alucinogenos
86
    {
87 11
        return $this->_alucinogenos;
88
    }
89
90 11
    public function opiaceos(): Opiaceos
91
    {
92 11
        return $this->_opiaceos;
93
    }
94
95 11
    public function otros(): Otros
96
    {
97 11
        return $this->_otros;
98
    }
99
}
100