x Sorry, these patches are not available anymore due to data migration. Please run a fresh inspection.
Passed
Push — master ( 1d5a7e...f5ffe9 )
by Brent
02:21
created

WidthScaler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B scale() 6 26 4

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\ResponsiveImage;
6
use Intervention\Image\Image;
7
8
class WidthScaler extends AbstractScaler
9
{
10
11
    /**
12
     * @param ResponsiveImage $responsiveImage
13
     * @param Image           $imageObject
14
     *
15
     * @return ResponsiveImage
16
     */
17
    public function scale(ResponsiveImage $responsiveImage, Image $imageObject) {
18
        $width = $imageObject->getWidth();
19
        $height = $imageObject->getHeight();
20
        $fileName = $responsiveImage->getFileName();
21
        $extension = $responsiveImage->getExtension();
22
        $urlPath = $responsiveImage->getUrlPath();
23
24
        while ($width >= $this->minWidth) {
25
            $scaledName = "{$fileName}-{$width}.{$extension}";
26
            $scaledSrc = "{$urlPath}/{$scaledName}";
27
            $responsiveImage->addSource($scaledSrc, $width);
28
29
            $publicScaledPath = "{$this->publicPath}/{$urlPath}/{$scaledName}";
30 View Code Duplication
            if (!$this->enableCache || !$this->fs->exists($publicScaledPath)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
31
                $this->fs->dumpFile(
32
                    $publicScaledPath,
33
                    $imageObject->resize($width, $height)->encode($extension)
34
                );
35
            }
36
37
            $width = floor($width * $this->stepModifier);
38
            $height = floor($height * $this->stepModifier);
39
        }
40
41
        return $responsiveImage;
42
    }
43
}
44