RectangularFromTwoPointsTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 30.77 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A count_provider() 0 10 1
A test_count() 8 8 1
A point_belongs_to_rectangular_provider() 0 14 1
A test_point_belongs_to_rectangular() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Cgi\Calc\Tests\Field;
4
5
use Cgi\Calc\Field\RectangularFromTwoPoints;
6
use Cgi\Calc\Point;
7
8
class RectangularFromTwoPointsTest extends \PHPUnit_Framework_TestCase
9
{
10
    public function count_provider()
11
    {
12
        return [
13
            [new Point(1,1), new Point(1, 1), 1],
14
            [new Point(1,1), new Point(2, 2), 4],
15
            [new Point(1,1), new Point(3, 3), 9],
16
17
            [new Point(1,1), new Point(4, 3), 12],
18
        ];
19
    }
20
21
    /**
22
     * @dataProvider count_provider
23
     */
24 View Code Duplication
    public function test_count(Point $lowerLeft, Point $upperRight, $expectedCount)
0 ignored issues
show
Duplication introduced by
This method 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...
25
    {
26
        $producer = new RectangularFromTwoPoints($lowerLeft, $upperRight);
27
        $field = $producer->produce();
28
29
        $actualCount = $field->count();
30
        static::assertEquals($expectedCount, $actualCount);
31
    }
32
33
    public function point_belongs_to_rectangular_provider()
34
    {
35
        return [
36
            [new Point(1,1), new Point(4, 3), new Point(1,1), true],
37
            [new Point(1,1), new Point(4, 3), new Point(2,2), true],
38
            [new Point(1,1), new Point(4, 3), new Point(3,3), true],
39
            [new Point(1,1), new Point(4, 3), new Point(4,3), true],
40
41
            [new Point(1,1), new Point(4, 3), new Point(0,0), false],
42
            [new Point(1,1), new Point(4, 3), new Point(0,4), false],
43
            [new Point(1,1), new Point(4, 3), new Point(4,4), false],
44
            [new Point(1,1), new Point(4, 3), new Point(4,0), false],
45
        ];
46
    }
47
48
    /**
49
     * @dataProvider point_belongs_to_rectangular_provider
50
     */
51 View Code Duplication
    public function test_point_belongs_to_rectangular(Point $lowerLeft, Point $upperRight, Point $testPoint, $expectedIn)
0 ignored issues
show
Duplication introduced by
This method 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...
52
    {
53
        $producer = new RectangularFromTwoPoints($lowerLeft, $upperRight);
54
        $field = $producer->produce();
55
56
        $actualIn = $field->contains($testPoint);
57
        static::assertEquals($expectedIn, $actualIn);
58
    }
59
}
60