FileAnalyzer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 22
rs 9.2
c 1
b 1
f 0
cc 1
eloc 19
nc 1
nop 9

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
3
/*
4
 * (c) Jean-François Lépine <https://twitter.com/Halleck45>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Hal\Application\Command\Job\Analyze;
11
use Hal\Component\OOP\Extractor\ClassMap;
12
use Hal\Component\OOP\Extractor\Extractor;
13
use Hal\Metrics\Complexity\Component\McCabe\McCabe;
14
use Hal\Metrics\Complexity\Component\Myer\Myer;
15
use Hal\Metrics\Complexity\Text\Halstead\Halstead;
16
use Hal\Metrics\Complexity\Text\Length\Loc;
17
use Hal\Metrics\Design\Component\MaintainabilityIndex\MaintainabilityIndex;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
21
/**
22
 * Starts analyze of one file
23
 *
24
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
25
 */
26
class FileAnalyzer
27
{
28
29
    /**
30
     * Output
31
     *
32
     * @var \Symfony\Component\Console\Output\OutputInterface
33
     */
34
    private $output;
35
36
    /**
37
     * do OOP analyze ?
38
     *
39
     * @var bool
40
     */
41
    private $withOOP;
42
43
    /**
44
     * @var Halstead
45
     */
46
    private $halstead;
47
48
    /**
49
     * @var MaintainabilityIndex
50
     */
51
    private $maintainabilityIndex;
52
53
    /**
54
     * @var Loc
55
     */
56
    private $loc;
57
58
    /**
59
     * @var McCabe
60
     */
61
    private $mcCabe;
62
63
    /**
64
     * @var Myer
65
     */
66
    private $myer;
67
68
    /**
69
     * @var Extractor
70
     */
71
    private $extractor;
72
73
    /**
74
     * @var \Hal\Component\OOP\Extractor\ClassMap
75
     */
76
    private $classMap;
77
78
    /**
79
     * Constructor
80
     *
81
     * @param OutputInterface $output
82
     * @param boolean $withOOP
83
     * @param Extractor $extractor
84
     * @param Halstead $halstead
85
     * @param Loc $loc
86
     * @param MaintainabilityIndex $maintainabilityIndex
87
     * @param McCabe $mcCabe
88
     * @param Myer $myer
89
     * @param ClassMap $classMap
90
     */
91
    public function __construct(
92
        OutputInterface $output
93
        , $withOOP
94
        , Extractor $extractor
95
        , Halstead $halstead
96
        , Loc $loc
97
        , MaintainabilityIndex $maintainabilityIndex
98
        , McCabe $mcCabe
99
        , Myer $myer
100
        , ClassMap $classMap
101
    )
102
    {
103
        $this->extractor = $extractor;
104
        $this->halstead = $halstead;
105
        $this->loc = $loc;
106
        $this->maintainabilityIndex = $maintainabilityIndex;
107
        $this->mcCabe = $mcCabe;
108
        $this->myer = $myer;
109
        $this->output = $output;
110
        $this->withOOP = $withOOP;
111
        $this->classMap = $classMap;
112
    }
113
114
115
    /**
116
     * Run analyze
117
     *
118
     * @param $filename
119
     * @return \Hal\Component\Result\ResultSet
120
     */
121
    public function execute($filename) {
122
123
        $rHalstead = $this->halstead->calculate($filename);
124
        $rLoc = $this->loc->calculate($filename);
125
        $rMcCabe = $this->mcCabe->calculate($filename);
126
        $rMyer = $this->myer->calculate($filename);
127
        $rMaintainability = $this->maintainabilityIndex->calculate($rHalstead, $rLoc, $rMcCabe);
128
129
        $resultSet = new \Hal\Component\Result\ResultSet($filename);
130
        $resultSet
131
            ->setLoc($rLoc)
132
            ->setMcCabe($rMcCabe)
133
            ->setMyer($rMyer)
134
            ->setHalstead($rHalstead)
135
            ->setMaintainabilityIndex($rMaintainability);
136
137
        if($this->withOOP) {
138
            $rOOP = $this->extractor->extract($filename);
139
            $this->classMap->push($filename, $rOOP);
140
            $resultSet->setOOP($rOOP);
141
        }
142
143
        return $resultSet;
144
    }
145
146
}
147