Completed
Pull Request — master (#10)
by dan
09:38
created

FocusCropDataCalculatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 65.38 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 51
loc 78
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFocusCropData() 0 21 1
A testGetFocusCropDataWithVerticalStyle() 17 17 1
A testGetFocusCropDataHorizontalStyle() 17 17 1
A testGetFocusCropDataStyleAnCropMatch() 17 17 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
 * This file is part of the IrishDan\ResponsiveImageBundle package.
4
 *
5
 * (c) Daniel Byrne <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source
8
 * code.
9
 */
10
11
namespace IrishDan\ResponsiveImageBundle\Tests\ImageProcessing;
12
13
14
use IrishDan\ResponsiveImageBundle\ImageProcessing\FocusCropDataCalculator;
15
use IrishDan\ResponsiveImageBundle\Tests\ResponsiveImageTestCase;
16
17
class FocusCropDataCalculatorTest extends ResponsiveImageTestCase
18
{
19
    public function testGetFocusCropData()
20
    {
21
        $focusOffsetFinder = new FocusCropDataCalculator(
22
            [10, 10, 90, 90],
23
            [40, 40, 60, 60],
24
            30,
25
            60
26
        );
27
28
        $focusCropData = $focusOffsetFinder->getFocusCropData();
29
30
        $this->assertArrayHasKey('width', $focusCropData);
31
        $this->assertArrayHasKey('height', $focusCropData);
32
        $this->assertArrayHasKey('x', $focusCropData);
33
        $this->assertArrayHasKey('y', $focusCropData);
34
35
        $this->assertTrue($focusCropData['width'] < 80);
36
        $this->assertTrue($focusCropData['height'] >= 80);
37
        $this->assertTrue($focusCropData['x'] >= 10);
38
        $this->assertTrue($focusCropData['y'] >= 10);
39
    }
40
41 View Code Duplication
    public function testGetFocusCropDataWithVerticalStyle()
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...
42
    {
43
        $focusOffsetFinder = new FocusCropDataCalculator(
44
            [10, 10, 90, 90],
45
            [40, 40, 60, 60],
46
            30,
47
            60
48
        );
49
50
        $focusCropData = $focusOffsetFinder->getFocusCropData();
51
52
        // for vertical style
53
        $this->assertTrue($focusCropData['width'] < $focusCropData['height']);
54
        $this->assertEquals($focusCropData['height'], 80);
55
        $this->assertTrue($focusCropData['x'] > 10);
56
        $this->assertTrue($focusCropData['y'] == 10);
57
    }
58
59 View Code Duplication
    public function testGetFocusCropDataHorizontalStyle()
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...
60
    {
61
        $focusOffsetFinder = new FocusCropDataCalculator(
62
            [10, 10, 90, 90],
63
            [40, 40, 60, 60],
64
            60,
65
            30
66
        );
67
68
        $focusCropData = $focusOffsetFinder->getFocusCropData();
69
70
        // for horizontal style
71
        $this->assertTrue($focusCropData['width'] > $focusCropData['height']);
72
        $this->assertEquals($focusCropData['width'], 80);
73
        $this->assertTrue($focusCropData['x'] == 10);
74
        $this->assertTrue($focusCropData['y'] > 10);
75
    }
76
77 View Code Duplication
    public function testGetFocusCropDataStyleAnCropMatch()
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...
78
    {
79
        $focusOffsetFinder = new FocusCropDataCalculator(
80
            [10, 10, 90, 90],
81
            [40, 40, 60, 60],
82
            60,
83
            60
84
        );
85
86
        $focusCropData = $focusOffsetFinder->getFocusCropData();
87
88
        // for horizontal style
89
        $this->assertTrue($focusCropData['width'] == $focusCropData['height']);
90
        $this->assertEquals($focusCropData['width'], 80);
91
        $this->assertTrue($focusCropData['x'] == 10);
92
        $this->assertTrue($focusCropData['y'] == 10);
93
    }
94
}
95