@@ -28,17 +28,17 @@ discard block |
||
28 | 28 | public function validateImageSize($attribute, $value, $parameters) |
29 | 29 | { |
30 | 30 | |
31 | - $image = $this->getImagePath( $value ); |
|
31 | + $image = $this->getImagePath($value); |
|
32 | 32 | |
33 | 33 | // Get the image dimension info, or fail. |
34 | 34 | |
35 | - $image_size = @getimagesize( $image ); |
|
35 | + $image_size = @getimagesize($image); |
|
36 | 36 | if ($image_size===false) return false; |
37 | 37 | |
38 | 38 | |
39 | 39 | // If only one dimension rule is passed, assume it applies to both height and width. |
40 | 40 | |
41 | - if ( !isset($parameters[1]) ) |
|
41 | + if (!isset($parameters[1])) |
|
42 | 42 | { |
43 | 43 | $parameters[1] = $parameters[0]; |
44 | 44 | } |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | // ">300" - dimension must be greater than 300 pixels |
52 | 52 | // ">=300" - dimension must be greater than or equal to 300 pixels |
53 | 53 | |
54 | - $width_check = $this->checkDimension( $parameters[0], $image_size[0] ); |
|
55 | - $height_check = $this->checkDimension( $parameters[1], $image_size[1] ); |
|
54 | + $width_check = $this->checkDimension($parameters[0], $image_size[0]); |
|
55 | + $height_check = $this->checkDimension($parameters[1], $image_size[1]); |
|
56 | 56 | |
57 | 57 | return $width_check['pass'] && $height_check['pass']; |
58 | 58 | |
@@ -70,15 +70,15 @@ discard block |
||
70 | 70 | public function replaceImageSize($message, $attribute, $rule, $parameters) |
71 | 71 | { |
72 | 72 | |
73 | - $width = $height = $this->checkDimension( $parameters[0] ); |
|
74 | - if ( isset($parameters[1]) ) |
|
73 | + $width = $height = $this->checkDimension($parameters[0]); |
|
74 | + if (isset($parameters[1])) |
|
75 | 75 | { |
76 | - $height = $this->checkDimension( $parameters[1] ); |
|
76 | + $height = $this->checkDimension($parameters[1]); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | return str_replace( |
80 | - array( ':width', ':height' ), |
|
81 | - array( $width['message'], $height['message'] ), |
|
80 | + array(':width', ':height'), |
|
81 | + array($width['message'], $height['message']), |
|
82 | 82 | $message |
83 | 83 | ); |
84 | 84 | |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | public function validateImageAspect($attribute, $value, $parameters) |
96 | 96 | { |
97 | 97 | |
98 | - $image = $this->getImagePath( $value ); |
|
98 | + $image = $this->getImagePath($value); |
|
99 | 99 | |
100 | 100 | // Get the image dimension info, or fail. |
101 | 101 | |
102 | - $image_size = @getimagesize( $image ); |
|
102 | + $image_size = @getimagesize($image); |
|
103 | 103 | if ($image_size===false) return false; |
104 | 104 | |
105 | 105 | $image_width = $image_size[0]; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | $both_orientations = false; |
119 | 119 | |
120 | - if (substr($parameters[0],0,1)=='~') |
|
120 | + if (substr($parameters[0], 0, 1)=='~') |
|
121 | 121 | { |
122 | 122 | $parameters[0] = substr($parameters[0], 1); |
123 | 123 | $both_orientations = true; |
@@ -134,19 +134,19 @@ discard block |
||
134 | 134 | |
135 | 135 | if ($aspect_width==0 || $aspect_height==0) |
136 | 136 | { |
137 | - throw new \RuntimeException('Aspect is zero or infinite: ' . $parameters[0] ); |
|
137 | + throw new \RuntimeException('Aspect is zero or infinite: ' . $parameters[0]); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $check = ($image_width * $aspect_height) / $aspect_width; |
141 | 141 | |
142 | - if (round($check) == $image_height) |
|
142 | + if (round($check)==$image_height) |
|
143 | 143 | { |
144 | 144 | return true; |
145 | 145 | } |
146 | 146 | |
147 | - if ( $both_orientations ) { |
|
147 | + if ($both_orientations) { |
|
148 | 148 | $check = ($image_width * $aspect_width) / $aspect_height; |
149 | - if (round($check) == $image_height) |
|
149 | + if (round($check)==$image_height) |
|
150 | 150 | { |
151 | 151 | return true; |
152 | 152 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function replaceImageAspect($message, $attribute, $rule, $parameters) |
170 | 170 | { |
171 | - return str_replace( ':aspect', join(':', $parameters), $message ); |
|
171 | + return str_replace(':aspect', join(':', $parameters), $message); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
@@ -179,24 +179,24 @@ discard block |
||
179 | 179 | * @param integer $dimension |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - protected function checkDimension($rule, $dimension=0) |
|
182 | + protected function checkDimension($rule, $dimension = 0) |
|
183 | 183 | { |
184 | 184 | |
185 | 185 | $dimension = intval($dimension); |
186 | 186 | |
187 | - if ($rule == '*') |
|
187 | + if ($rule=='*') |
|
188 | 188 | { |
189 | 189 | $message = $this->translator->trans('image-validator::validation.anysize'); |
190 | 190 | $pass = true; |
191 | 191 | } |
192 | - else if ( preg_match('/^(\d+)\-(\d+)$/', $rule, $matches) ) |
|
192 | + else if (preg_match('/^(\d+)\-(\d+)$/', $rule, $matches)) |
|
193 | 193 | { |
194 | 194 | $size1 = intval($matches[1]); |
195 | 195 | $size2 = intval($matches[2]); |
196 | - $message = $this->translator->trans('image-validator::validation.between', compact('size1','size2')); |
|
196 | + $message = $this->translator->trans('image-validator::validation.between', compact('size1', 'size2')); |
|
197 | 197 | $pass = ($dimension >= $size1) && ($dimension <= $size2); |
198 | 198 | } |
199 | - else if ( preg_match('/^([<=>]*)(\d+)$/', $rule, $matches) ) |
|
199 | + else if (preg_match('/^([<=>]*)(\d+)$/', $rule, $matches)) |
|
200 | 200 | { |
201 | 201 | |
202 | 202 | $size = intval($matches[2]); |
@@ -222,33 +222,33 @@ discard block |
||
222 | 222 | case '=': |
223 | 223 | case '': |
224 | 224 | $message = $this->translator->trans('image-validator::validation.equal', compact('size')); |
225 | - $pass = $dimension == $size; |
|
225 | + $pass = $dimension==$size; |
|
226 | 226 | break; |
227 | 227 | default: |
228 | - throw new \RuntimeException('Unknown image size validation rule: ' . $rule ); |
|
228 | + throw new \RuntimeException('Unknown image size validation rule: ' . $rule); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | } |
232 | 232 | else |
233 | 233 | { |
234 | - throw new \RuntimeException('Unknown image size validation rule: ' . $rule ); |
|
234 | + throw new \RuntimeException('Unknown image size validation rule: ' . $rule); |
|
235 | 235 | } |
236 | 236 | |
237 | - return compact('message','pass'); |
|
237 | + return compact('message', 'pass'); |
|
238 | 238 | |
239 | 239 | } |
240 | 240 | |
241 | - protected function getImagePath( $value ) |
|
241 | + protected function getImagePath($value) |
|
242 | 242 | { |
243 | 243 | |
244 | 244 | // if were passed an instance of UploadedFile, return the path |
245 | - if ( $value instanceof UploadedFile ) |
|
245 | + if ($value instanceof UploadedFile) |
|
246 | 246 | { |
247 | 247 | return $value->getPathname(); |
248 | 248 | } |
249 | 249 | |
250 | 250 | // if we're passed a PHP file upload array, return the "tmp_name" |
251 | - if ( is_array($value) && array_get($value, 'tmp_name') !== null) { |
|
251 | + if (is_array($value) && array_get($value, 'tmp_name')!==null) { |
|
252 | 252 | return $value['tmp_name']; |
253 | 253 | } |
254 | 254 |
@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function boot() |
28 | 28 | { |
29 | - $this->loadTranslationsFrom(__DIR__.'/../lang', 'image-validator'); |
|
29 | + $this->loadTranslationsFrom(__DIR__ . '/../lang', 'image-validator'); |
|
30 | 30 | |
31 | 31 | $messages = trans('image-validator::validation'); |
32 | 32 | |
33 | 33 | $this->app->bind('Cviebrock\ImageValidator\ImageValidator', function($app) use ($messages) |
34 | 34 | { |
35 | - $validator = new ImageValidator($app['translator'], [], [], $messages ); |
|
35 | + $validator = new ImageValidator($app['translator'], [], [], $messages); |
|
36 | 36 | |
37 | 37 | if (isset($app['validation.presence'])) |
38 | 38 | { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | protected function addNewRules() |
63 | 63 | { |
64 | - foreach($this->getRules() as $rule) |
|
64 | + foreach ($this->getRules() as $rule) |
|
65 | 65 | { |
66 | 66 | $this->extendValidator($rule); |
67 | 67 | } |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | protected function extendValidator($rule) |
77 | 77 | { |
78 | 78 | $method = studly_case($rule); |
79 | - $translation = $this->app['translator']->trans('image-validator::validation.'.$rule); |
|
79 | + $translation = $this->app['translator']->trans('image-validator::validation.' . $rule); |
|
80 | 80 | $this->app['validator']->extend($rule, 'Cviebrock\ImageValidator\ImageValidator@validate' . $method, $translation); |
81 | - $this->app['validator']->replacer($rule, 'Cviebrock\ImageValidator\ImageValidator@replace' . $method ); |
|
81 | + $this->app['validator']->replacer($rule, 'Cviebrock\ImageValidator\ImageValidator@replace' . $method); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 |