Conditions | 27 |
Paths | 2305 |
Total Lines | 109 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
49 | private function get_crop_dimensions($image_width, $image_height) |
||
50 | { |
||
51 | if ('false' === $this->smart_crop) { |
||
52 | return ['width' => $this->container_width, 'height' => $this->container_height]; |
||
53 | } |
||
54 | |||
55 | $container_width = $this->container_width; |
||
56 | $container_height = $this->container_height; |
||
57 | |||
58 | /** |
||
59 | * Slideshow Width == Slide Width |
||
60 | */ |
||
61 | if ($image_width == $container_width && $image_height == $container_height) { |
||
62 | $new_slide_width = $container_width; |
||
63 | $new_slide_height = $container_height; |
||
64 | } |
||
65 | |||
66 | if ($image_width == $container_width && $image_height < $container_height) { |
||
67 | $new_slide_height = $image_height; |
||
68 | $new_slide_width = $container_width / ($container_height / $image_height); |
||
69 | } |
||
70 | |||
71 | if ($image_width == $container_width && $image_height > $container_height) { |
||
72 | $new_slide_width = $container_width; |
||
73 | $new_slide_height = $container_height; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Slideshow Width < Slide Width |
||
78 | */ |
||
79 | if ($image_width < $container_width && $image_height == $container_height) { |
||
80 | $new_slide_width = $image_width; |
||
81 | $new_slide_height = $image_height / ($container_width / $image_width); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Slide is smaller than slidehow - both width and height |
||
86 | */ |
||
87 | if ($image_width < $container_width && $image_height < $container_height) { |
||
88 | if ($container_width > $container_height) { |
||
89 | // wide |
||
90 | |||
91 | if ($image_width > $image_height) { |
||
92 | // wide |
||
93 | $new_slide_height = $image_height; |
||
94 | $new_slide_width = $container_width / ($container_height / $image_height); |
||
95 | |||
96 | if ($new_slide_width > $image_width) { |
||
97 | $new_slide_width = $image_width; |
||
98 | $new_slide_height = $container_height / ($container_width / $image_width); |
||
99 | } |
||
100 | } else { |
||
101 | // tall |
||
102 | $new_slide_width = $image_width; |
||
103 | $new_slide_height = $container_height / ($container_width / $image_width); |
||
104 | |||
105 | if ($new_slide_height > $image_height) { |
||
106 | $new_slide_height = $image_height; |
||
107 | $new_slide_width = $container_width / ($container_height / $image_height); |
||
108 | } |
||
109 | } |
||
110 | } else { |
||
111 | // tall |
||
112 | if ($image_width > $image_height) { |
||
113 | // wide |
||
114 | $new_slide_height = $image_height; |
||
115 | $new_slide_width = $container_width / ($container_height / $image_height); |
||
116 | |||
117 | if ($new_slide_width > $image_width) { |
||
118 | $new_slide_width = $image_width; |
||
119 | $new_slide_height = $container_height / ($container_width / $image_width); |
||
120 | } |
||
121 | } else { |
||
122 | // tall |
||
123 | $new_slide_width = $image_width; |
||
124 | $new_slide_height = $container_height / ($container_width / $image_width); |
||
125 | |||
126 | if ($new_slide_height > $image_height) { |
||
127 | $new_slide_height = $image_height; |
||
128 | $new_slide_width = $container_width / ($container_height / $image_height); |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | |||
134 | if ($image_width < $container_width && $image_height > $container_height) { |
||
135 | $new_slide_width = $image_width; |
||
136 | $new_slide_height = $container_height / ($container_width / $image_width); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Slideshow Width > Slide Width |
||
141 | */ |
||
142 | if ($image_width > $container_width && $image_height == $container_height) { |
||
143 | $new_slide_width = $container_width; |
||
144 | $new_slide_height = $container_height; |
||
145 | } |
||
146 | |||
147 | if ($image_width > $container_width && $image_height < $container_height) { |
||
148 | $new_slide_height = $image_height; |
||
149 | $new_slide_width = $container_width / ($container_height / $image_height); |
||
150 | } |
||
151 | |||
152 | if ($image_width > $container_width && $image_height > $container_height) { |
||
153 | $new_slide_width = $container_width; |
||
154 | $new_slide_height = $container_height; |
||
155 | } |
||
156 | |||
157 | return ['width' => floor($new_slide_width), 'height' => floor($new_slide_height)]; |
||
158 | } |
||
321 |