Abstractness   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
c 1
b 1
f 0
lcom 0
cbo 1
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A calculate() 0 19 4
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\Metrics\Mood\Abstractness;
11
use Hal\Component\Result\ResultCollection;
12
13
14
/**
15
 * Estimates Abstractness of package
16
 *
17
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
18
 */
19
class Abstractness {
20
21
    /**
22
     * Calculate abstractness
23
     *
24
     * @param ResultCollection $results Array of ResultSet
25
     * @return Result
26
     */
27
    public function calculate(ResultCollection $results) {
28
29
        $ac = $cc = $abstractness = 0;
30
31
        foreach($results as $result) {
32
            $rOOP = $result->getOOP();
33
            if(is_object($rOOP)) {
34
                $cc += sizeof($rOOP->getConcreteClasses(), COUNT_NORMAL);
35
                $ac += sizeof($rOOP->getAbstractClasses(), COUNT_NORMAL);
36
            }
37
        }
38
39
        $result = new Result;
40
        if($ac + $cc > 0) {
41
            $abstractness = round($ac / ($ac + $cc), 2);
42
        }
43
        $result->setAbstractness($abstractness);
44
        return $result;
45
    }
46
47
};
48