Passed
Push — master ( 1d5a7e...f5ffe9 )
by Brent
02:21
created

FileSizeScalerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 33.8 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 24
loc 71
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A __destruct() 0 5 2
A setUp() 0 5 1
A test_scale_down() 8 8 1
A createResponsiveImage() 8 8 1
A createImageObject() 0 5 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 Brendt\Image\Tests\Phpunit\Scaler;
4
5
use Brendt\Image\Config\DefaultConfigurator;
6
use Brendt\Image\ResponsiveImage;
7
use Brendt\Image\Scaler\FileSizeScaler;
8
use Intervention\Image\ImageManager;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\Filesystem\Filesystem;
11
12
class FileSizeScalerTest extends TestCase
13
{
14
15
    /**
16
     * @var Filesystem
17
     */
18
    private $fs;
19
20
    /**
21
     * @var string
22
     */
23
    private $publicPath = './tests/public';
24
25
    /**
26
     * @var FileSizeScaler
27
     */
28
    private $scaler;
29
30
    /**
31
     * @var ImageManager
32
     */
33
    private $engine;
34
35 View Code Duplication
    public function __construct() {
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...
36
        parent::__construct();
37
38
        $this->fs = new Filesystem();
39
        $this->engine = new ImageManager([
40
            'driver' => 'gd',
41
        ]);
42
    }
43
44
    public function __destruct() {
45
        if ($this->fs->exists($this->publicPath)) {
46
            $this->fs->remove($this->publicPath);
47
        }
48
    }
49
50
    public function setUp() {
51
        $this->scaler = new FileSizeScaler(new DefaultConfigurator([
52
            'publicPath' => $this->publicPath,
53
        ]));
54
    }
55
56 View Code Duplication
    public function test_scale_down() {
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...
57
        $responsiveImage = $this->createResponsiveImage();
58
        $imageObject = $this->createImageObject();
59
60
        $responsiveImage = $this->scaler->scale($responsiveImage, $imageObject);
61
62
        $this->assertTrue(count($responsiveImage->getSrcset()) > 1);
63
    }
64
65
    // TODO: test algorithm
66
67 View Code Duplication
    private function createResponsiveImage() {
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...
68
        $responsiveImage = new ResponsiveImage('img/image.jpeg');
69
        $responsiveImage->setExtension('jpeg');
70
        $responsiveImage->setFileName('image');
71
        $responsiveImage->setUrlPath('/img');
72
73
        return $responsiveImage;
74
    }
75
76
    private function createImageObject() {
77
        $imageObject = $this->engine->make('./tests/img/image.jpeg');
78
79
        return $imageObject;
80
    }
81
82
}
83