Completed
Push — master ( bdaaad...4f4372 )
by personal
06:57 queued 04:36
created

ProbablyBugged::getLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Hal\Violation\Class_;
3
4
5
use Hal\Metric\ClassMetric;
6
use Hal\Metric\Metric;
7
use Hal\Violation\Violation;
8
9 View Code Duplication
class ProbablyBugged implements Violation
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
12
    /**
13
     * @inheritdoc
14
     */
15
    public function getName()
16
    {
17
        return 'Probably bugged';
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function apply(Metric $metric)
24
    {
25
        if (!$metric instanceof ClassMetric) {
26
            return;
27
        }
28
29
        $this->metric = $metric;
0 ignored issues
show
Bug introduced by
The property metric does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
31
        $suspect = 0;
0 ignored issues
show
Unused Code introduced by
$suspect is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
32
        if ($metric->get('bugs') >= .35) {
33
            $metric->get('violations')->add($this);
0 ignored issues
show
Bug introduced by
The method add cannot be called on $metric->get('violations') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
34
            return;
35
        }
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function getLevel()
42
    {
43
        return Violation::WARNING;
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function getDescription()
50
    {
51
        return <<<EOT
52
This component contains in theory {$this->metric->get('bugs')} bugs.
53
54
* Calculation is based on number of operators, operands, cyclomatic complexity
55
* See more details at https://en.wikipedia.org/wiki/Halstead_complexity_measures
56
* {$this->metric->get('numberOfUnitTests')} testsuites has dependency to this class.
57
58
Maybe you should check yor unit tests for this class.
59
EOT;
60
61
    }
62
}
63