Passed
Push — ft/fragments ( b30041...2bbc06 )
by Ben
07:30
created
src/Fragments/FragmentField.php 2 patches
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.