ReadabilityFactor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A calculate() 0 7 1
A getName() 0 3 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 ReadabilityFactor 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(5.8, 18, $bound->getAverage('difficulty'))
46
            , $this->calculator->highIsBetter(42, 32, $bound->getAverage('commentWeight'))
47
        );
48
        return round(array_sum($notes) / count($notes, COUNT_NORMAL), 2);
49
    }
50
51
    /**
52
     * @inheritedDoc
53
     */
54
    public function getName() {
55
        return 'Accessibility for new developers';
56
    }
57
}