VolumeFactor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Score\Factor;
11
12
use Hal\Application\Score\Calculator;
13
use Hal\Component\Bounds\Result\ResultInterface;
14
use Hal\Component\Result\ResultCollection;
15
16
/**
17
 * Is the code accessible for new developers ?
18
 *
19
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
20
 */
21
class VolumeFactor implements FactorInterface {
22
23
    /**
24
     * Bounds
25
     *
26
     * @var Calculator
27
     */
28
    private $calculator;
29
30
    /**
31
     * Constructor
32
     *
33
     * @param Calculator $calculator
34
     */
35
    public function __construct(Calculator $calculator)
36
    {
37
        $this->calculator = $calculator;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function calculate(ResultCollection $collection, ResultCollection $groupedResults, ResultInterface $bound) {
44
        $notes = array(
45
            $this->calculator->lowIsBetter(65, 154, $bound->getAverage('loc'))
46
        , $this->calculator->highIsBetter(9, 30, $bound->getAverage('logicalLoc'))
47
        , $this->calculator->highIsBetter(27, 59, $bound->getAverage('vocabulary'))
48
        );
49
        return round(array_sum($notes) / count($notes, COUNT_NORMAL), 2);
50
    }
51
52
    /**
53
     * @inheritedDoc
54
     */
55
    public function getName() {
56
        return 'Volume';
57
    }
58
}