FileSizeScaler   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 35
Duplicated Lines 17.14 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 6
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C scale() 6 25 12

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 Intervention\Image\Image;
6
use Symfony\Component\Finder\SplFileInfo;
7
8
class FileSizeScaler extends AbstractScaler
9
{
10
11
    /**
12
     * @param SplFileInfo $sourceFile
13
     * @param Image       $imageObject
14
     *
15
     * @return array
16
     */
17
    public function scale(SplFileInfo $sourceFile, Image $imageObject) : array {
18
        $fileSize = $sourceFile->getSize();
19
        $width = $imageObject->getWidth();
20
        $height = $imageObject->getHeight();
21
        $ratio = $height / $width;
22
        $area = $width * $width * $ratio;
23
        $pixelPrice = $fileSize / $area;
24
        
25
        $sizes = [];
26
27 View Code Duplication
        if ($this->includeSource && (!$this->maxWidth || $width <= $this->maxWidth) && (!$this->maxFileSize || $fileSize <= $this->maxFileSize)) {
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...
28
            $sizes[$width] = $height;
29
        }
30
31
        do {
32
            $fileSize = $fileSize * $this->stepModifier;
33
            $newWidth = floor(sqrt(($fileSize / $pixelPrice) / $ratio));
34
35 View Code Duplication
            if ((!$this->maxFileSize || $fileSize <= $this->maxFileSize) && (!$this->maxWidth || $newWidth <= $this->maxWidth)) {
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...
36
                $sizes[(int) $newWidth] = (int) $newWidth * $ratio;
37
            }
38
        } while ($fileSize > $this->minFileSize && $newWidth > $this->minWidth);
39
40
        return $sizes;
41
    }
42
}
43