Image::resizeByHeight()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
/**
3
 * Image.php
4
 * @author Revin Roman http://phptime.ru
5
 */
6
7
namespace rmrevin\yii\module\File\component;
8
9
use Imagine;
10
11
/**
12
 * Class Image
13
 * @package rmrevin\yii\module\File\component
14
 */
15
class Image extends \yii\imagine\Image
16
{
17
18
    /**
19
     * Resize an image by width.
20
     *
21
     * For example,
22
     *
23
     * ~~~
24
     * $obj->resizeByWidth('path\to\image.jpg', 200);
25
     * $obj->resizeByWidth('path\to\image.jpg', 150, \Imagine\Image\ImageInterface::FILTER_UNDEFINED);
26
     * ~~~
27
     *
28
     * @param string $filename the image file path or path alias.
29
     * @param integer $width the resize width
30
     * @param string $filter
31
     * @return \Imagine\Image\ImageInterface
32
     */
33 1 View Code Duplication
    public static function resizeByWidth($filename, $width, $filter = Imagine\Image\ImageInterface::FILTER_UNDEFINED)
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...
34
    {
35 1
        $img = static::getImagine()
36 1
            ->open(\Yii::getAlias($filename));
0 ignored issues
show
Bug introduced by
It seems like \Yii::getAlias($filename) targeting yii\BaseYii::getAlias() can also be of type boolean; however, Imagine\Image\ImagineInterface::open() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
37
38 1
        $height = $img->getSize()->getHeight() / $img->getSize()->getWidth() * $width;
39
40
        return $img
41 1
            ->copy()
42 1
            ->resize(new Imagine\Image\Box($width, $height), $filter);
43
    }
44
45
    /**
46
     * Resize an image by height.
47
     *
48
     * For example,
49
     *
50
     * ~~~
51
     * $obj->resizeByHeight('path\to\image.jpg', 200);
52
     * $obj->resizeByHeight('path\to\image.jpg', 250, \Imagine\Image\ImageInterface::FILTER_UNDEFINED);
53
     * ~~~
54
     *
55
     * @param string $filename the image file path or path alias.
56
     * @param integer $height the resize height
57
     * @param string $filter
58
     * @return \Imagine\Image\ImageInterface
59
     */
60 1 View Code Duplication
    public static function resizeByHeight($filename, $height, $filter = Imagine\Image\ImageInterface::FILTER_UNDEFINED)
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
    {
62 1
        $img = static::getImagine()
63 1
            ->open(\Yii::getAlias($filename));
0 ignored issues
show
Bug introduced by
It seems like \Yii::getAlias($filename) targeting yii\BaseYii::getAlias() can also be of type boolean; however, Imagine\Image\ImagineInterface::open() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
64
65 1
        $width = $img->getSize()->getWidth() / $img->getSize()->getHeight() * $height;
66
67
        return $img
68 1
            ->copy()
69 1
            ->resize(new Imagine\Image\Box($width, $height), $filter);
70
    }
71
72
    /**
73
     * Strict resize an image.
74
     *
75
     * For example,
76
     *
77
     * ~~~
78
     * $obj->resize('path\to\image.jpg', 200, 200);
79
     * $obj->resize('path\to\image.jpg', 150, 250, \Imagine\Image\ImageInterface::FILTER_UNDEFINED);
80
     * ~~~
81
     *
82
     * @param string $filename the image file path or path alias.
83
     * @param integer $width the resize width
84
     * @param integer $height the resize height
85
     * @param string $filter
86
     * @return \Imagine\Image\ImageInterface
87
     */
88 1
    public static function resize($filename, $width, $height, $filter = Imagine\Image\ImageInterface::FILTER_UNDEFINED)
89
    {
90 1
        return static::getImagine()
91 1
            ->open(\Yii::getAlias($filename))
0 ignored issues
show
Bug introduced by
It seems like \Yii::getAlias($filename) targeting yii\BaseYii::getAlias() can also be of type boolean; however, Imagine\Image\ImagineInterface::open() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
92 1
            ->copy()
93 1
            ->resize(new Imagine\Image\Box($width, $height), $filter);
94
    }
95
}