Passed
Push — master ( f99852...46c8e4 )
by Brent
04:34 queued 02:08
created

FileSizeScalerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 11.59 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 8
loc 69
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 createImageObject() 0 5 1
A createSourceFile() 0 6 1
A test_scale_down() 0 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 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
use Symfony\Component\Finder\Finder;
12
13
class FileSizeScalerTest extends TestCase
14
{
15
16
    /**
17
     * @var Filesystem
18
     */
19
    private $fs;
20
21
    /**
22
     * @var string
23
     */
24
    private $publicPath = './tests/public';
25
26
    /**
27
     * @var FileSizeScaler
28
     */
29
    private $scaler;
30
31
    /**
32
     * @var ImageManager
33
     */
34
    private $engine;
35
36 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...
37
        parent::__construct();
38
39
        $this->fs = new Filesystem();
40
        $this->engine = new ImageManager([
41
            'driver' => 'gd',
42
        ]);
43
    }
44
45
    public function __destruct() {
46
        if ($this->fs->exists($this->publicPath)) {
47
            $this->fs->remove($this->publicPath);
48
        }
49
    }
50
51
    public function setUp() {
52
        $this->scaler = new FileSizeScaler(new DefaultConfigurator([
53
            'publicPath' => $this->publicPath,
54
        ]));
55
    }
56
57
    public function test_scale_down() {
58
        $sourceFile = $this->createSourceFile();
59
        $imageObject = $this->createImageObject();
60
61
        $sizes = $this->scaler->scale($sourceFile, $imageObject);
62
63
        $this->assertTrue(count($sizes) > 1);
64
    }
65
66
    // TODO: test algorithm
67
68
    private function createImageObject() {
69
        $imageObject = $this->engine->make('./tests/img/image.jpeg');
70
71
        return $imageObject;
72
    }
73
74
    private function createSourceFile() {
75
        $sourceFiles = Finder::create()->files()->in('./tests/img')->name('image.jpeg')->getIterator();
76
        $sourceFiles->rewind();
77
78
        return $sourceFiles->current();
79
    }
80
81
}
82