Passed
Push — ft/fragments ( eb1d17...53a8e6 )
by Philippe
07:33
created
src/DynamicAttributes/HasDynamicAttributes.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,11 +22,11 @@  discard block
 block discarded – undo
22 22
             return false;
23 23
         }
24 24
 
25
-        if(in_array($key, $this->dynamicKeys())) {
25
+        if (in_array($key, $this->dynamicKeys())) {
26 26
             return true;
27 27
         }
28 28
 
29
-        if(in_array('*', $this->dynamicKeys())){
29
+        if (in_array('*', $this->dynamicKeys())) {
30 30
             return !in_array($key, $this->dynamicKeysBlacklist());
31 31
         }
32 32
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
             $value = $this->dynamic($key);
114 114
 
115 115
             // If value is localized, we wont return the entire value, but instead return null since no fallback will be provided.
116
-            if(is_array($value) && in_array($locale, $this->dynamicLocales())) return null;
116
+            if (is_array($value) && in_array($locale, $this->dynamicLocales())) return null;
117 117
 
118 118
             return $value;
119 119
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -113,7 +113,9 @@
 block discarded – undo
113 113
             $value = $this->dynamic($key);
114 114
 
115 115
             // If value is localized, we wont return the entire value, but instead return null since no fallback will be provided.
116
-            if(is_array($value) && in_array($locale, $this->dynamicLocales())) return null;
116
+            if(is_array($value) && in_array($locale, $this->dynamicLocales())) {
117
+                return null;
118
+            }
117 119
 
118 120
             return $value;
119 121
         }
Please login to merge, or discard this patch.
src/DynamicAttributes/DynamicAttributes.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,11 +16,11 @@
 block discarded – undo
16 16
 
17 17
     public static function fromRawValue($value): self
18 18
     {
19
-        if($value instanceof self) return $value;
19
+        if ($value instanceof self) return $value;
20 20
 
21 21
         $value = is_null($value) ? [] : (is_array($value) ? $value : json_decode($value, true));
22 22
 
23
-        return new static((array) $value);
23
+        return new static((array)$value);
24 24
     }
25 25
 
26 26
     public function has(string $key): bool
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@
 block discarded – undo
16 16
 
17 17
     public static function fromRawValue($value): self
18 18
     {
19
-        if($value instanceof self) return $value;
19
+        if($value instanceof self) {
20
+            return $value;
21
+        }
20 22
 
21 23
         $value = is_null($value) ? [] : (is_array($value) ? $value : json_decode($value, true));
22 24
 
Please login to merge, or discard this patch.
src/Fragments/ManagesFragments.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -21,16 +21,16 @@
 block discarded – undo
21 21
         }, $payload);
22 22
 
23 23
         // remove all dead fragments
24
-        $this->existingModel()->removeAllFragments($fragmentField->getKey(), array_map(function (Fragment $fragment) {
24
+        $this->existingModel()->removeAllFragments($fragmentField->getKey(), array_map(function(Fragment $fragment) {
25 25
             return $fragment->hasModelId() ? $fragment->getModelId() : null;
26 26
         }, $fragments));
27 27
 
28 28
         // Save each fragment
29
-        foreach($fragments as $i => $fragment) {
29
+        foreach ($fragments as $i => $fragment) {
30 30
             $modelId = $this->existingModel()->saveFragment($fragment, $i);
31 31
 
32 32
             // Attach any asset
33
-            if(isset($imagePayload[$i])) {
33
+            if (isset($imagePayload[$i])) {
34 34
                 $fieldKey = key($imagePayload[$i]);
35 35
                 $imageField = $this->fields()->keyed($fragmentField->getKey())->first()->getFields()->keyed($fieldKey)->first();
36 36
 
Please login to merge, or discard this patch.
src/Fragments/HasFragments.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@
 block discarded – undo
23 23
             'key' => $fragment->getKey(), 'order' => $order,
24 24
         ], $fragment->getValues());
25 25
 
26
-        if($fragment->hasModelId()){
27
-            $model =FragmentModel::find($fragment->getModelId());
26
+        if ($fragment->hasModelId()) {
27
+            $model = FragmentModel::find($fragment->getModelId());
28 28
             $model->update($values);
29 29
 
30 30
             return $model->id;
Please login to merge, or discard this patch.
src/Fragments/FragmentField.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -60,21 +60,21 @@
 block discarded – undo
60 60
                 ->setModelIdInputName($this->name.'[' . $k . '][modelId]')
61 61
                 ->setFields($this->fields->clone()->map(function(Field $field) use($k, $fragment){
62 62
                     return $field->name($this->name.'.' . $k . '.' . $field->getName())
63
-                                 ->localizedFormat(':name.:locale')
64
-                                 ->valueResolver(function($model = null, $locale = null, $field) use($fragment){
63
+                                    ->localizedFormat(':name.:locale')
64
+                                    ->valueResolver(function($model = null, $locale = null, $field) use($fragment){
65 65
 
66
-                                     if(isset($field->value)) return $field->value;
66
+                                        if(isset($field->value)) return $field->value;
67 67
 
68
-                                     if($field instanceof MediaField){
69
-                                         if(!$fragment->hasModelId()){
70
-                                             return [];
71
-                                         }
68
+                                        if($field instanceof MediaField){
69
+                                            if(!$fragment->hasModelId()){
70
+                                                return [];
71
+                                            }
72 72
 
73
-                                         return $field->getMedia(FragmentModel::find($fragment->getModelId()), $locale);
74
-                                     }
73
+                                            return $field->getMedia(FragmentModel::find($fragment->getModelId()), $locale);
74
+                                        }
75 75
 
76
-                                     return $fragment->getValue($field->getColumn(), $locale);
77
-                                 });
76
+                                        return $fragment->getValue($field->getColumn(), $locale);
77
+                                    });
78 78
                 }));
79 79
         }
80 80
 
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -42,31 +42,31 @@  discard block
 block discarded – undo
42 42
         $fragments = [Fragment::empty($this->getKey())];
43 43
 
44 44
         // Model is auto-injected by Manager::editFields() method.
45
-        if(($this->model)) {
45
+        if (($this->model)) {
46 46
 
47
-            if(!method_exists($this->model, 'getFragments')) {
48
-                throw new \RuntimeException(get_class($this->model) . ' is missing the ' . HasFragments::class . ' trait.');
47
+            if (!method_exists($this->model, 'getFragments')) {
48
+                throw new \RuntimeException(get_class($this->model).' is missing the '.HasFragments::class.' trait.');
49 49
             }
50 50
 
51
-            if(count($modelFragments = $this->model->getFragments($this->getKey())) > 0) {
52
-                $fragments = $modelFragments->map(function (FragmentModel $fragmentModel) {
51
+            if (count($modelFragments = $this->model->getFragments($this->getKey())) > 0) {
52
+                $fragments = $modelFragments->map(function(FragmentModel $fragmentModel) {
53 53
                     return Fragment::fromModel($fragmentModel);
54 54
                 })->all();
55 55
             }
56 56
         }
57 57
 
58
-        foreach($fragments as $k => $fragment) {
58
+        foreach ($fragments as $k => $fragment) {
59 59
             $fragments[$k] = $fragments[$k]
60
-                ->setModelIdInputName($this->name.'[' . $k . '][modelId]')
60
+                ->setModelIdInputName($this->name.'['.$k.'][modelId]')
61 61
                 ->setFields($this->fields->clone()->map(function(Field $field) use($k, $fragment){
62
-                    return $field->name($this->name.'.' . $k . '.' . $field->getName())
62
+                    return $field->name($this->name.'.'.$k.'.'.$field->getName())
63 63
                                  ->localizedFormat(':name.:locale')
64 64
                                  ->valueResolver(function($model = null, $locale = null, $field) use($fragment){
65 65
 
66
-                                     if(isset($field->value)) return $field->value;
66
+                                     if (isset($field->value)) return $field->value;
67 67
 
68
-                                     if($field instanceof MediaField){
69
-                                         if(!$fragment->hasModelId()){
68
+                                     if ($field instanceof MediaField) {
69
+                                         if (!$fragment->hasModelId()) {
70 70
                                              return [];
71 71
                                          }
72 72
 
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 
84 84
     public function getDuplicatableFields(): array
85 85
     {
86
-        if(count($this->getFragments()) < 1) return [];
86
+        if (count($this->getFragments()) < 1) return [];
87 87
 
88 88
         // Take the fields from the first fragment as a starting point for duplication
89
-        return array_map(function(\Thinktomorrow\Chief\Fields\Types\Field $field){
90
-            return $field->valueResolver(function($model = null, $locale = null, $field){
91
-                if($field instanceof \Thinktomorrow\Chief\Fields\Types\MediaField) { return []; }
89
+        return array_map(function(\Thinktomorrow\Chief\Fields\Types\Field $field) {
90
+            return $field->valueResolver(function($model = null, $locale = null, $field) {
91
+                if ($field instanceof \Thinktomorrow\Chief\Fields\Types\MediaField) { return []; }
92 92
                 return null;
93 93
             })->render();
94 94
         }, $this->getFragments()[0]->getFields()->clone()->all());
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,7 +63,9 @@  discard block
 block discarded – undo
63 63
                                  ->localizedFormat(':name.:locale')
64 64
                                  ->valueResolver(function($model = null, $locale = null, $field) use($fragment){
65 65
 
66
-                                     if(isset($field->value)) return $field->value;
66
+                                     if(isset($field->value)) {
67
+                                         return $field->value;
68
+                                     }
67 69
 
68 70
                                      if($field instanceof MediaField){
69 71
                                          if(!$fragment->hasModelId()){
@@ -83,7 +85,9 @@  discard block
 block discarded – undo
83 85
 
84 86
     public function getDuplicatableFields(): array
85 87
     {
86
-        if(count($this->getFragments()) < 1) return [];
88
+        if(count($this->getFragments()) < 1) {
89
+            return [];
90
+        }
87 91
 
88 92
         // Take the fields from the first fragment as a starting point for duplication
89 93
         return array_map(function(\Thinktomorrow\Chief\Fields\Types\Field $field){
Please login to merge, or discard this patch.
src/Fragments/Fragment.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
     public static function fromModel(FragmentModel $fragmentModel): self
35 35
     {
36
-        return new static($fragmentModel->key, $fragmentModel->values->all(), new Fields(), (int) $fragmentModel->id);
36
+        return new static($fragmentModel->key, $fragmentModel->values->all(), new Fields(), (int)$fragmentModel->id);
37 37
     }
38 38
 
39 39
     public static function fromNew(string $key, array $values): self
@@ -48,14 +48,14 @@  discard block
 block discarded – undo
48 48
 
49 49
     public static function fromRequestPayload(string $key, array $payload): self
50 50
     {
51
-        if(!isset($payload['modelId'])) {
51
+        if (!isset($payload['modelId'])) {
52 52
             return static::fromNew($key, $payload);
53 53
         }
54 54
 
55 55
         $modelId = $payload['modelId'];
56 56
         unset($payload['modelId']);
57 57
 
58
-        return new static($key, $payload, new Fields(), (int) $modelId);
58
+        return new static($key, $payload, new Fields(), (int)$modelId);
59 59
     }
60 60
 
61 61
     public function setFields(Fields $fields): self
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 
73 73
     public function getValue(string $key, ?string $locale = null)
74 74
     {
75
-        if(!isset($this->values[$key])) {
75
+        if (!isset($this->values[$key])) {
76 76
             return null;
77 77
         }
78 78
 
79 79
         // When the value is an array, it is assumed that this is an array of locales, each representing the value for that locale
80
-        if(is_array($this->values[$key])) {
81
-            if($locale && array_key_exists($locale, $this->values[$key])) {
80
+        if (is_array($this->values[$key])) {
81
+            if ($locale && array_key_exists($locale, $this->values[$key])) {
82 82
                 return $this->values[$key][$locale];
83 83
             }
84 84
         }
Please login to merge, or discard this patch.
src/Pages/PageManager.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             $this->pageBuilderField(),
89 89
             InputField::make('title')->translatable($this->model->availableLocales())
90 90
                 ->validation('required-fallback-locale|max:200', [], [
91
-                    'trans.' . config('app.fallback_locale', 'nl') . '.title' => 'title',
91
+                    'trans.'.config('app.fallback_locale', 'nl').'.title' => 'title',
92 92
                 ])
93 93
                 ->label('Intern label')
94 94
                 ->description('Dit is de benaming die zal worden getoond in de admin selectie velden.')
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
             if (is_array_empty($translation)) {
211 211
 
212 212
                 // Nullify all values
213
-                $trans[$locale] = array_map(function ($value) {
213
+                $trans[$locale] = array_map(function($value) {
214 214
                     return null;
215 215
                 }, $translation);
216 216
                 continue;
Please login to merge, or discard this patch.