testRuleAppliesForValueGreaterThanThreshold()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD\Rule\Design;
19
20
use PHPMD\AbstractTest;
21
22
/**
23
 * Test case for the excessive long class rule.
24
 *
25
 * @covers \PHPMD\Rule\Design\LongClass
26
 */
27 View Code Duplication
class LongClassTest extends AbstractTest
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...
28
{
29
    /**
30
     * Tests that the rule applies for a value greater than the configured
31
     * threshold.
32
     *
33
     * @return void
34
     */
35
    public function testRuleAppliesForValueGreaterThanThreshold()
36
    {
37
        $class  = $this->getClassMock('loc', 42);
38
        $report = $this->getReportMock(1);
39
40
        $rule = new LongClass();
41
        $rule->setReport($report);
42
        $rule->addProperty('minimum', '41');
43
        $rule->addProperty('ignore-whitespace', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
        $rule->apply($class);
45
    }
46
47
    /**
48
     * Test that the rule applies for a value that is equal with the configured
49
     * threshold.
50
     *
51
     * @return void
52
     */
53
    public function testRuleAppliesForValueEqualToThreshold()
54
    {
55
        $class  = $this->getClassMock('loc', 42);
56
        $report = $this->getReportMock(1);
57
58
        $rule = new LongClass();
59
        $rule->setReport($report);
60
        $rule->addProperty('minimum', '42');
61
        $rule->addProperty('ignore-whitespace', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
        $rule->apply($class);
63
    }
64
65
    /**
66
     * Tests that the rule does not apply when the value is at least one lower
67
     * than the threshold.
68
     *
69
     * @return void
70
     */
71
    public function testRuleDoesNotApplyForValueLowerThanThreshold()
72
    {
73
        $class  = $this->getClassMock('loc', 22);
74
        $report = $this->getReportMock(0);
75
76
        $rule = new LongClass();
77
        $rule->setReport($report);
78
        $rule->addProperty('minimum', '23');
79
        $rule->addProperty('ignore-whitespace', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
        $rule->apply($class);
81
    }
82
83
    /**
84
     * Tests that the rule uses eloc when ignore whitespace is set
85
     *
86
     * @return void
87
     */
88
    public function testRuleUsesElocWhenIgnoreWhitespaceSet()
89
    {
90
        $class  = $this->getClassMock('eloc', 22);
91
        $report = $this->getReportMock(0);
92
93
        $rule = new LongClass();
94
        $rule->setReport($report);
95
        $rule->addProperty('minimum', '23');
96
        $rule->addProperty('ignore-whitespace', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
        $rule->apply($class);
98
    }
99
}
100