Conditions | 9 |
Paths | 11 |
Total Lines | 55 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
30 | public function apply(ImageInterface $image): ImageInterface |
||
31 | { |
||
32 | // full The complete image is returned, without any cropping. |
||
33 | // square The region is defined as an area where the width and height are both equal to the length of the shorter dimension of the complete image. The region may be positioned anywhere in the longer dimension of the image content at the server’s discretion, and centered is often a reasonable default. |
||
34 | // x,y,w,h The region of the full image to be returned is specified in terms of absolute pixel values. The value of x represents the number of pixels from the 0 position on the horizontal axis. The value of y represents the number of pixels from the 0 position on the vertical axis. Thus the x,y position 0,0 is the upper left-most pixel of the image. w represents the width of the region and h represents the height of the region in pixels. |
||
35 | // pct:x,y,w,h The region to be returned is specified as a sequence of percentages of the full image’s dimensions, as reported in the image information document. Thus, x represents the number of pixels from the 0 position on the horizontal axis, calculated as a percentage of the reported width. w represents the width of the region, also calculated as a percentage of the reported width. The same applies to y and h respectively. These may be floating point numbers. |
||
36 | |||
37 | if ($this->options[0] === 'full') { |
||
38 | return $image; |
||
39 | } |
||
40 | |||
41 | $this->width = $image->width(); |
||
42 | $this->height = $image->height(); |
||
43 | |||
44 | if ($this->options[0] === 'square') { |
||
45 | $shorter = $this->width < $this->height ? $this->width : $this->height; |
||
46 | |||
47 | return $image->cover($shorter, $shorter, 'center'); |
||
48 | } |
||
49 | |||
50 | if (strpos($this->options[0], 'pct:') === false) { |
||
51 | // iiif - x,y,w,h |
||
52 | $x = (int) $this->options[0]; |
||
53 | $y = (int) $this->options[1]; |
||
54 | $w = (int) $this->options[2]; |
||
55 | $h = (int) $this->options[3]; |
||
56 | |||
57 | if (($x + $w) > $this->width) { |
||
58 | $w = $w - (($x + $w) - $this->width); |
||
59 | } |
||
60 | |||
61 | if (($y + $h) > $this->height) { |
||
62 | $h = $h - (($y + $h) - $this->height); |
||
63 | } |
||
64 | |||
65 | // intervention - w,h,x,y |
||
66 | return $image->crop($w, $h, $x, $y); |
||
67 | } |
||
68 | |||
69 | // iiif - x,y,w,h |
||
70 | $x = (int) round($this->width * substr($this->options[0], 4) / 100); |
||
71 | $y = (int) round($this->height * $this->options[1] / 100); |
||
72 | $w = (int) round($this->width * $this->options[2] / 100); |
||
73 | $h = (int) round($this->height * $this->options[3] / 100); |
||
74 | |||
75 | if ($this->options[2] + substr($this->options[0], 4) > 100) { |
||
76 | $w = $this->width - $x; |
||
77 | } |
||
78 | |||
79 | if ($this->options[3] + $this->options[1] > 100) { |
||
80 | $h = $this->height - $y; |
||
81 | } |
||
82 | |||
83 | // intervention - w,h,x,y |
||
84 | return $image->crop($w, $h, $x, $y); |
||
85 | } |
||
87 |