ImageStylerTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 55 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 44
loc 80
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A tearDown() 0 5 1
A testCreateImage() 0 13 1
A testCreateImageWithScale() 14 14 1
A testCreateImageWithCrop() 15 15 1
A testCreateImageWithCoordinates() 15 15 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\Tests\ResponsiveImageTestCase;
15
16
class ImageStylerTest extends ResponsiveImageTestCase
17
{
18
    private $imager;
19
    private $testImagePath = __DIR__ . '/../Resources/dummy.jpg';
20
    private $generatedDirectory = __DIR__ . '/../Resources/generated/';
21
    private $coordinates = '100, 100, 900, 900:400, 500, 700, 800';
22
23
    public function setUp()
24
    {
25
        $this->imager = $this->getService('responsive_image.image_styler');
26
        $this->createDirectory($this->generatedDirectory);
27
    }
28
29
    public function tearDown()
30
    {
31
        parent::tearDown();
32
        $this->deleteDirectory($this->generatedDirectory);
33
    }
34
35
    public function testCreateImage()
36
    {
37
        $style = [
38
            'effect' => 'scale',
39
            'width'  => 200,
40
        ];
41
42
        $destination = $this->generatedDirectory . 'dummy.jpg';
43
        $this->imager->createImage($this->testImagePath, $destination, $style);
44
45
        $this->assertFileExists($destination);
46
        $this->assertEquals("image/jpeg", mime_content_type($destination));
47
    }
48
49 View Code Duplication
    public function testCreateImageWithScale()
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...
50
    {
51
        $style = [
52
            'effect' => 'scale',
53
            'width'  => 200,
54
        ];
55
56
        $destination = $this->generatedDirectory . 'dummy.jpg';
57
        $this->imager->createImage($this->testImagePath, $destination, $style);
58
59
        $this->assertFileExists($destination);
60
        $this->assertEquals("image/jpeg", mime_content_type($destination));
61
        $this->assertTrue(filesize($this->testImagePath) > filesize($destination));
62
    }
63
64 View Code Duplication
    public function testCreateImageWithCrop()
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...
65
    {
66
        $style = [
67
            'effect' => 'crop',
68
            'width'  => 200,
69
            'height' => 200,
70
        ];
71
72
        $destination = $this->generatedDirectory . 'dummy.jpg';
73
        $this->imager->createImage($this->testImagePath, $destination, $style);
74
75
        $this->assertFileExists($destination);
76
        $this->assertEquals("image/jpeg", mime_content_type($destination));
77
        $this->assertTrue(filesize($this->testImagePath) > filesize($destination));
78
    }
79
80 View Code Duplication
    public function testCreateImageWithCoordinates()
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...
81
    {
82
        $style = [
83
            'effect' => 'crop',
84
            'width'  => 200,
85
            'height' => 200,
86
        ];
87
88
        $destination = $this->generatedDirectory . 'dummy.jpg';
89
        $this->imager->createImage($this->testImagePath, $destination, $style, $this->coordinates);
90
91
        $this->assertFileExists($destination);
92
        $this->assertEquals("image/jpeg", mime_content_type($destination));
93
        $this->assertTrue(filesize($this->testImagePath) > filesize($destination));
94
    }
95
}
96