SizesScalerTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 35.9 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A __destruct() 0 5 2
A test_scale_down() 14 14 1
A test_scale_down_with_include_source() 14 14 1
A createImageObject() 0 5 1
A createSourceFile() 0 6 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\Scaler;
4
5
use Brendt\Image\Config\DefaultConfigurator;
6
use Intervention\Image\ImageManager;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\Filesystem\Filesystem;
9
use Symfony\Component\Finder\Finder;
10
11
class SizesScalerTest extends TestCase
12
{
13
14
    /**
15
     * @var Filesystem
16
     */
17
    private $fs;
18
19
    /**
20
     * @var string
21
     */
22
    private $publicPath = './tests/public';
23
24
    /**
25
     * @var ImageManager
26
     */
27
    private $engine;
28
29
30
    public function __construct() {
31
        parent::__construct();
32
33
        $this->fs = new Filesystem();
34
        $this->engine = new ImageManager([
35
            'driver' => 'gd',
36
        ]);
37
    }
38
39
    public function __destruct() {
40
        if ($this->fs->exists($this->publicPath)) {
41
            $this->fs->remove($this->publicPath);
42
        }
43
    }
44
45 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...
46
        $scaler = new SizesScaler(new DefaultConfigurator([
47
            'publicPath'    => $this->publicPath,
48
            'includeSource' => false,
49
        ]));
50
        $scaler->setSizes([500, 10000, 1920]);
51
52
        $sourceFile = $this->createSourceFile();
53
        $imageObject = $this->createImageObject();
54
55
        $sizes = $scaler->scale($sourceFile, $imageObject);
56
57
        $this->assertCount(2, $sizes);
58
    }
59
60 View Code Duplication
    public function test_scale_down_with_include_source() {
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...
61
        $scaler = new SizesScaler(new DefaultConfigurator([
62
            'publicPath'    => $this->publicPath,
63
            'includeSource' => true,
64
        ]));
65
        $scaler->setSizes([500, 800]);
66
67
        $sourceFile = $this->createSourceFile();
68
        $imageObject = $this->createImageObject();
69
70
        $sizes = $scaler->scale($sourceFile, $imageObject);
71
        
72
        $this->assertCount(3, $sizes);
73
    }
74
75
76
    private function createImageObject() {
77
        $imageObject = $this->engine->make('./tests/img/image.jpeg');
78
79
        return $imageObject;
80
    }
81
82
    private function createSourceFile() {
83
        $sourceFiles = Finder::create()->files()->in('./tests/img')->name('image.jpeg')->getIterator();
84
        $sourceFiles->rewind();
85
86
        return $sourceFiles->current();
87
    }
88
}
89