FileLackOfCohesionOfMethods   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A calculate() 0 22 3
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\Complexity\Structural\LCOM;
11
use Hal\Component\OOP\Extractor\ClassMap;
12
use Hal\Component\OOP\Reflected\ReflectedInterface;
13
14
15
/**
16
 * Estimates LCOM by file: average for all declared classes in this file
17
 *
18
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
19
 */
20
class FileLackOfCohesionOfMethods {
21
22
23
    /**
24
     * @var \Hal\Component\OOP\Extractor\ClassMap
25
     */
26
    private $classMap;
27
28
    /**
29
     * Constructor
30
     *
31
     * @param ClassMap $classMap
32
     */
33
    public function __construct(ClassMap $classMap)
34
    {
35
        $this->classMap = $classMap;
36
    }
37
38
39
    /**
40
     * Calculates lcom for file (and not for class)
41
     *
42
     * @param string $filename
43
     * @return Result
44
     */
45
    public function calculate($filename)
46
    {
47
        $rOOP = $this->classMap->getClassesIn($filename);
48
        $result = new Result($filename);
0 ignored issues
show
Unused Code introduced by
The call to Result::__construct() has too many arguments starting with $filename.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
49
50
        $n = 0;
51
        $lcom = new LackOfCohesionOfMethods();
52
53
        foreach($rOOP->getClasses() as $class) {
54
55
            if($class instanceof ReflectedInterface) {
56
                continue;
57
            }
58
59
            $r = $lcom->calculate($class);
60
            $n += $r->getLcom();
61
        }
62
63
        $result->setLcom($n);
64
65
        return $result;
66
    }
67
};