Test Failed
Push — fix/media-validation ( 3351fe )
by Ben
09:34
created
src/Fields/ValidationRules/ValidatesExistingAssetAttributes.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
     protected function refersToExistingAsset($value): bool
11 11
     {
12 12
         // Faster check to see if there is an asset id passed or not.
13
-        if(is_string($value) && $this->isValidJson($value)) return false;
13
+        if (is_string($value) && $this->isValidJson($value)) return false;
14 14
 
15 15
         return !is_null($this->existingAsset($value));
16 16
     }
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     {
36 36
         $filepath = $asset->media->first()->getPath();
37 37
 
38
-        if (! $sizeDetails = @getimagesize($filepath)) {
38
+        if (!$sizeDetails = @getimagesize($filepath)) {
39 39
             return false;
40 40
         }
41 41
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@
 block discarded – undo
10 10
     protected function refersToExistingAsset($value): bool
11 11
     {
12 12
         // Faster check to see if there is an asset id passed or not.
13
-        if(is_string($value) && $this->isValidJson($value)) return false;
13
+        if(is_string($value) && $this->isValidJson($value)) {
14
+            return false;
15
+        }
14 16
 
15 17
         return !is_null($this->existingAsset($value));
16 18
     }
Please login to merge, or discard this patch.
src/Fields/ValidationRules/FileFieldMaxRule.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,19 +11,19 @@  discard block
 block discarded – undo
11 11
     {
12 12
         $value = $this->normalizePayload($value);
13 13
 
14
-        foreach([MediaRequest::NEW, MediaRequest::REPLACE] as $type) {
15
-            foreach($value[$type] as $file) {
16
-                if($file && false !== $this->validateMax($attribute, $file, $params)) {
14
+        foreach ([MediaRequest::NEW, MediaRequest::REPLACE] as $type) {
15
+            foreach ($value[$type] as $file) {
16
+                if ($file && false !== $this->validateMax($attribute, $file, $params)) {
17 17
                     return true;
18 18
                 }
19 19
             }
20 20
         }
21 21
 
22 22
         $validator->setCustomMessages([
23
-            'filefield_max' => 'De :attribute is te groot en dient kleiner te zijn dan ' . implode(',',$params) .'Kb.',
23
+            'filefield_max' => 'De :attribute is te groot en dient kleiner te zijn dan '.implode(',', $params).'Kb.',
24 24
         ]);
25 25
 
26
-        if(!isset($validator->customAttributes[$attribute])) {
26
+        if (!isset($validator->customAttributes[$attribute])) {
27 27
             $validator->addCustomAttributes([
28 28
                 $attribute => 'afbeelding',
29 29
             ]);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
     public function validateMax($attribute, $value, $parameters)
37 37
     {
38
-        if($this->refersToExistingAsset($value)) {
38
+        if ($this->refersToExistingAsset($value)) {
39 39
             return $this->validateAssetMax($this->existingAsset($value), $parameters);
40 40
         }
41 41
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
      */
52 52
     protected function getSize($attribute, $value)
53 53
     {
54
-        if(!$value instanceof File) {
55
-            throw new \InvalidArgumentException('Value is expected to be of type ' . File::class);
54
+        if (!$value instanceof File) {
55
+            throw new \InvalidArgumentException('Value is expected to be of type '.File::class);
56 56
         }
57 57
 
58 58
         return $value->getSize() / 1024;
Please login to merge, or discard this patch.
src/Fields/ValidationRules/FileFieldRequiredRule.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
     {
11 11
         $value = $this->normalizePayload($value);
12 12
 
13
-        foreach([MediaRequest::NEW, MediaRequest::REPLACE] as $type) {
14
-            if(is_array($value[$type]) && !empty($value[$type])) {
13
+        foreach ([MediaRequest::NEW, MediaRequest::REPLACE] as $type) {
14
+            if (is_array($value[$type]) && !empty($value[$type])) {
15 15
                 return true;
16 16
             }
17 17
         }
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
             'filefield_required' => 'De :attribute is verplicht.',
21 21
         ]);
22 22
 
23
-        if(!isset($validator->customAttributes[$attribute])) {
23
+        if (!isset($validator->customAttributes[$attribute])) {
24 24
             $validator->addCustomAttributes([
25 25
                 $attribute => 'afbeelding',
26 26
             ]);
Please login to merge, or discard this patch.
src/Fields/Types/FileField.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
         $images = [];
26 26
         $locale = $locale ?? app()->getLocale();
27 27
 
28
-        $assets = $model->assetRelation->where('pivot.type', $this->getKey())->filter(function ($asset) use ($locale) {
28
+        $assets = $model->assetRelation->where('pivot.type', $this->getKey())->filter(function($asset) use ($locale) {
29 29
             return $asset->pivot->locale == $locale;
30 30
         })->sortBy('pivot.order');
31 31
 
Please login to merge, or discard this patch.
src/Fields/Types/FieldType.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,21 +4,21 @@  discard block
 block discarded – undo
4 4
 
5 5
 class FieldType
6 6
 {
7
-    const INPUT = 'input';   // oneliner text (input)
8
-    const TEXT = 'text';    // Plain text (textarea)
7
+    const INPUT = 'input'; // oneliner text (input)
8
+    const TEXT = 'text'; // Plain text (textarea)
9 9
     const NUMBER = 'number'; // number
10 10
     const RANGE = 'range'; // range slider
11
-    const DATE = 'date';    // Timestamp input
12
-    const PHONENUMBER = 'phonenumber';    // Timestamp input
13
-    const HTML = 'html';    // Html text (wysiwyg)
14
-    const SELECT = 'select';  // Select options
11
+    const DATE = 'date'; // Timestamp input
12
+    const PHONENUMBER = 'phonenumber'; // Timestamp input
13
+    const HTML = 'html'; // Html text (wysiwyg)
14
+    const SELECT = 'select'; // Select options
15 15
     //const MEDIA = 'media';  // media file
16
-    const FILE = 'file';  // regular file
17
-    const IMAGE = 'image';  // image (slim uploader)
18
-    const DOCUMENT = 'document';  // documents
19
-    const RADIO = 'radio';  // radio select
20
-    const CHECKBOX = 'checkbox';  // checkbox select
21
-    const PAGEBUILDER = 'pagebuilder';  // the most special field there is...
16
+    const FILE = 'file'; // regular file
17
+    const IMAGE = 'image'; // image (slim uploader)
18
+    const DOCUMENT = 'document'; // documents
19
+    const RADIO = 'radio'; // radio select
20
+    const CHECKBOX = 'checkbox'; // checkbox select
21
+    const PAGEBUILDER = 'pagebuilder'; // the most special field there is...
22 22
 
23 23
     /** @var string */
24 24
     private $type;
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     public function equalsAny(array $types): bool
49 49
     {
50 50
         foreach ($types as $type) {
51
-            if ($this->equals( FieldType::fromString($type) )) {
51
+            if ($this->equals(FieldType::fromString($type))) {
52 52
                 return true;
53 53
             }
54 54
         }
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
     public function equals($type): bool
60 60
     {
61
-        return ((string) $type === (string) $this->type && static::class === get_class($type));
61
+        return ((string)$type === (string)$this->type && static::class === get_class($type));
62 62
     }
63 63
 
64 64
     public function __toString()
Please login to merge, or discard this patch.
src/Fields/Types/AbstractField.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types = 1);
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace Thinktomorrow\Chief\Fields\Types;
4 4
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 
105 105
     protected function getValidationNameFormat(): string
106 106
     {
107
-        if($this->isLocalized()) {
107
+        if ($this->isLocalized()) {
108 108
             return $this->getLocalizedNameFormat();
109 109
         }
110 110
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
     protected function getLocalizedNameFormat(): string
115 115
     {
116
-        if(false !== strpos($this->name, ':locale')){
116
+        if (false !== strpos($this->name, ':locale')) {
117 117
             return $this->name;
118 118
         }
119 119
 
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
      */
238 238
     private function defaultEloquentValueResolver(): \Closure
239 239
     {
240
-        return function (Model $model = null, $locale = null) {
240
+        return function(Model $model = null, $locale = null) {
241 241
 
242
-            if(!$model) return $this->value;
242
+            if (!$model) return $this->value;
243 243
 
244 244
             if ($locale && $this->isLocalized()) {
245 245
                 return $model->getTranslationFor($this->getColumn(), $locale);
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
             return false;
273 273
         }
274 274
 
275
-        if($this->getValidationParameters() instanceof ValidationParameters) {
275
+        if ($this->getValidationParameters() instanceof ValidationParameters) {
276 276
             foreach ($this->getValidationParameters()->getRules() as $rule) {
277 277
                 if (false !== strpos($rule, 'required')) {
278 278
                     return true;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 
286 286
     public function optional(): bool
287 287
     {
288
-        return ! $this->required();
288
+        return !$this->required();
289 289
     }
290 290
 
291 291
     public function getValidationNames(array $payload = []): array
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 
392 392
     public function getElementView(): string
393 393
     {
394
-        if($this->elementView) return $this->elementView;
394
+        if ($this->elementView) return $this->elementView;
395 395
 
396 396
         return $this->isLocalized()
397 397
             ? 'chief::back._fields.translatable'
Please login to merge, or discard this patch.
src/Fields/Types/ImageField.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
         $images = [];
31 31
         $locale = $locale ?? app()->getLocale();
32 32
 
33
-        $assets = $model->assetRelation->where('pivot.type', $this->getKey())->filter(function ($asset) use ($locale) {
33
+        $assets = $model->assetRelation->where('pivot.type', $this->getKey())->filter(function($asset) use ($locale) {
34 34
             return $asset->pivot->locale == $locale;
35 35
         })->sortBy('pivot.order');
36 36
 
Please login to merge, or discard this patch.
src/Fields/SavingFields.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 //            }
42 42
 
43 43
             // Custom set methods - default is the generic setField() method.
44
-            $methodName = 'set'. ucfirst(Str::camel($field->getKey())) . 'Field';
44
+            $methodName = 'set'.ucfirst(Str::camel($field->getKey())).'Field';
45 45
             (method_exists($this, $methodName))
46 46
                 ? $this->$methodName($field, $request)
47 47
                 : $this->setField($field, $request);
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
 
59 59
     protected function detectCustomSaveMethods(Field $field): bool
60 60
     {
61
-        $saveMethodByKey = 'save'. ucfirst(Str::camel($field->getKey())) . 'Field';
62
-        $saveMethodByType = 'save'. ucfirst(Str::camel($field->getType()->get())) . 'Fields';
61
+        $saveMethodByKey = 'save'.ucfirst(Str::camel($field->getKey())).'Field';
62
+        $saveMethodByType = 'save'.ucfirst(Str::camel($field->getType()->get())).'Fields';
63 63
 
64
-        foreach([$saveMethodByKey, $saveMethodByType] as $saveMethod){
64
+        foreach ([$saveMethodByKey, $saveMethodByType] as $saveMethod) {
65 65
 
66 66
             foreach ($this->assistants() as $assistant) {
67 67
                 if (method_exists($assistant, $saveMethod)) {
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 
103 103
             // Make our media fields able to be translatable as well...
104 104
             if ($field->ofType(FieldType::FILE, FieldType::IMAGE, FieldType::DOCUMENT)) {
105
-                throw new \Exception('Cannot process the ' . $field->getKey() . ' media field. Currently no support for translatable media files. We should fix this!');
105
+                throw new \Exception('Cannot process the '.$field->getKey().' media field. Currently no support for translatable media files. We should fix this!');
106 106
             }
107 107
 
108 108
             // Okay so this is a bit odd but since all translations are expected to be inside the trans
Please login to merge, or discard this patch.
src/Media/Application/AbstractMediaFieldHandler.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,11 +31,11 @@
 block discarded – undo
31 31
      */
32 32
     protected function sluggifyFilename(string $filename): string
33 33
     {
34
-        if(false === strpos($filename, '.')) return $filename;
34
+        if (false === strpos($filename, '.')) return $filename;
35 35
 
36
-        $extension = substr($filename, strrpos($filename, '.') + 1);
36
+        $extension = substr($filename, strrpos($filename, '.')+1);
37 37
         $filename = substr($filename, 0, strrpos($filename, '.'));
38 38
 
39
-        return Str::slug($filename) . '.' . $extension;
39
+        return Str::slug($filename).'.'.$extension;
40 40
     }
41 41
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@
 block discarded – undo
31 31
      */
32 32
     protected function sluggifyFilename(string $filename): string
33 33
     {
34
-        if(false === strpos($filename, '.')) return $filename;
34
+        if(false === strpos($filename, '.')) {
35
+            return $filename;
36
+        }
35 37
 
36 38
         $extension = substr($filename, strrpos($filename, '.') + 1);
37 39
         $filename = substr($filename, 0, strrpos($filename, '.'));
Please login to merge, or discard this patch.