Passed
Push — ft/fields-refactor ( 34e13a...220f3b )
by Ben
81:47
created
src/Modules/Module.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,11 +63,11 @@
 block discarded – undo
63 63
 
64 64
     public static function managedModelKey(): string
65 65
     {
66
-        if(isset(static::$managedModelKey)){
66
+        if (isset(static::$managedModelKey)) {
67 67
             return static::$managedModelKey;
68 68
         }
69 69
 
70
-        throw new \Exception('Missing required static property \'managedModelKey\' on ' . static::class. '.');
70
+        throw new \Exception('Missing required static property \'managedModelKey\' on '.static::class.'.');
71 71
     }
72 72
 
73 73
     /**
Please login to merge, or discard this patch.
src/Pages/Page.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 
81 81
     public static function managedModelKey(): string
82 82
     {
83
-        if(isset(static::$managedModelKey)){
83
+        if (isset(static::$managedModelKey)) {
84 84
             return static::$managedModelKey;
85 85
         }
86 86
 
87
-        throw new \Exception('Missing required static property \'managedModelKey\' on ' . static::class. '.');
87
+        throw new \Exception('Missing required static property \'managedModelKey\' on '.static::class.'.');
88 88
     }
89 89
 
90 90
     /**
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
     public function flatReferenceLabel(): string
125 125
     {
126 126
         if ($this->exists) {
127
-            $status = ! $this->isPublished() ? ' [' . $this->statusAsPlainLabel().']' : null;
127
+            $status = !$this->isPublished() ? ' ['.$this->statusAsPlainLabel().']' : null;
128 128
 
129
-            return $this->title ? $this->title . $status : '';
129
+            return $this->title ? $this->title.$status : '';
130 130
         }
131 131
 
132 132
         return '';
Please login to merge, or discard this patch.
src/Common/Helpers/Memoize.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,8 +35,8 @@
 block discarded – undo
35 35
 
36 36
     private function convertToCachableParameters(array $parameters)
37 37
     {
38
-        foreach($parameters as $key => $value) {
39
-            if($value instanceof Model) $parameters[$key] = get_class($value) . '@' . $value->id;
38
+        foreach ($parameters as $key => $value) {
39
+            if ($value instanceof Model) $parameters[$key] = get_class($value).'@'.$value->id;
40 40
         }
41 41
 
42 42
         return $parameters;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@
 block discarded – undo
36 36
     private function convertToCachableParameters(array $parameters)
37 37
     {
38 38
         foreach($parameters as $key => $value) {
39
-            if($value instanceof Model) $parameters[$key] = get_class($value) . '@' . $value->id;
39
+            if($value instanceof Model) {
40
+                $parameters[$key] = get_class($value) . '@' . $value->id;
41
+            }
40 42
         }
41 43
 
42 44
         return $parameters;
Please login to merge, or discard this patch.
src/Fields/Types/Field.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Thinktomorrow\Chief\Fields\Types;
6 6
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
     public function name(string $name = null)
53 53
     {
54
-        if(!is_null($name)) {
54
+        if (!is_null($name)) {
55 55
             $this->values['name'] = $name;
56 56
 
57 57
             return $this;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     {
87 87
         $name = $this->name();
88 88
 
89
-        if(strpos($name, ':locale')) {
89
+        if (strpos($name, ':locale')) {
90 90
             return preg_replace('#(:locale)#', $locale, $name);
91 91
         }
92 92
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
         }
176 176
 
177 177
         if (!in_array($name, ['label', 'key', 'description', 'column', 'name', 'prepend', 'append'])) {
178
-            throw new \InvalidArgumentException('Cannot set value by ['. $name .'].');
178
+            throw new \InvalidArgumentException('Cannot set value by ['.$name.'].');
179 179
         }
180 180
 
181 181
         $this->values[$name] = $arguments[0];
Please login to merge, or discard this patch.
src/Settings/Settings.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 
23 23
         if (is_array($this->items[$key])) {
24 24
 
25
-            if(!$locale) $locale = app()->getLocale();
25
+            if (!$locale) $locale = app()->getLocale();
26 26
 
27 27
             if ($this->items[$key] == null || !isset($this->items[$key][$locale])) {
28 28
                 return $default;
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@
 block discarded – undo
22 22
 
23 23
         if (is_array($this->items[$key])) {
24 24
 
25
-            if(!$locale) $locale = app()->getLocale();
25
+            if(!$locale) {
26
+                $locale = app()->getLocale();
27
+            }
26 28
 
27 29
             if ($this->items[$key] == null || !isset($this->items[$key][$locale])) {
28 30
                 return $default;
Please login to merge, or discard this patch.
src/Urls/UrlRecord.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
     public static function getByModel(Model $model)
66 66
     {
67 67
         return static::where('model_type', $model->getMorphClass())
68
-                     ->where('model_id', $model->id)
69
-                     ->get();
68
+                        ->where('model_id', $model->id)
69
+                        ->get();
70 70
     }
71 71
 
72 72
     public static function findRecentRedirect(Model $model, string $locale): ?self
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
         if ($ignoredModel) {
135 135
             $builder->whereNotIn('id', function ($query) use ($ignoredModel) {
136 136
                 $query->select('id')
137
-                      ->from('chief_urls')
138
-                      ->where('model_type', '=', $ignoredModel->getMorphClass())
139
-                      ->where('model_id', '=', $ignoredModel->id);
137
+                        ->from('chief_urls')
138
+                        ->where('model_type', '=', $ignoredModel->getMorphClass())
139
+                        ->where('model_id', '=', $ignoredModel->id);
140 140
             });
141 141
         }
142 142
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         return static::where('model_type', $model->getMorphClass())
75 75
             ->where('model_id', $model->id)
76 76
             ->where('locale', $locale)
77
-            ->where('redirect_id','<>', null)
77
+            ->where('redirect_id', '<>', null)
78 78
             ->orderBy('redirect_id', 'ASC')
79 79
             ->first();
80 80
     }
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
             $builder->where('locale', $locale);
128 128
         }
129 129
 
130
-        if (! $includeRedirects) {
130
+        if (!$includeRedirects) {
131 131
             $builder->whereNull('redirect_id');
132 132
         }
133 133
 
134 134
         if ($ignoredModel) {
135
-            $builder->whereNotIn('id', function ($query) use ($ignoredModel) {
135
+            $builder->whereNotIn('id', function($query) use ($ignoredModel) {
136 136
                 $query->select('id')
137 137
                       ->from('chief_urls')
138 138
                       ->where('model_type', '=', $ignoredModel->getMorphClass())
Please login to merge, or discard this patch.
src/Urls/Application/SaveUrlSlugs.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     private function saveRecord(string $locale, ?string $slug)
57 57
     {
58 58
         // Existing ones for this locale?
59
-        $nonRedirectsWithSameLocale = $this->existingRecords->filter(function ($record) use ($locale) {
59
+        $nonRedirectsWithSameLocale = $this->existingRecords->filter(function($record) use ($locale) {
60 60
             return (
61 61
                 $record->locale == $locale &&
62 62
                 !$record->isRedirect()
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
         // If slug entry is left empty, all existing records will be deleted
67 67
         if (!$slug) {
68
-            $nonRedirectsWithSameLocale->each(function ($existingRecord) {
68
+            $nonRedirectsWithSameLocale->each(function($existingRecord) {
69 69
                 $existingRecord->delete();
70 70
             });
71 71
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         }
82 82
 
83 83
         // Only replace the existing records that differ from the current passed slugs
84
-        $nonRedirectsWithSameLocale->each(function ($existingRecord) use ($slug) {
84
+        $nonRedirectsWithSameLocale->each(function($existingRecord) use ($slug) {
85 85
             if ($existingRecord->slug != $slug) {
86 86
                 $existingRecord->replaceAndRedirect(['slug' => $slug]);
87 87
             }
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
      */
127 127
     private function deleteIdenticalRedirects($existingRecords, $locale, $slug): void
128 128
     {
129
-        $existingRecords->filter(function ($record) use ($locale) {
129
+        $existingRecords->filter(function($record) use ($locale) {
130 130
             return (
131 131
                 $record->locale == $locale &&
132 132
                 $record->isRedirect()
133 133
             );
134
-        })->each(function ($existingRecord) use ($slug) {
134
+        })->each(function($existingRecord) use ($slug) {
135 135
             if ($existingRecord->slug == $slug) {
136 136
                 $existingRecord->delete();
137 137
             }
@@ -140,15 +140,15 @@  discard block
 block discarded – undo
140 140
 
141 141
     private function deleteIdenticalRecords($existingRecords): void
142 142
     {
143
-        if($this->strict) return;
143
+        if ($this->strict) return;
144 144
 
145 145
         // The old homepage url should be removed since this is no longer in effect.
146 146
         // In case of any redirect to this old homepage, the last used redirect is now back in effect.
147
-        $existingRecords->reject(function($existingRecord){
147
+        $existingRecords->reject(function($existingRecord) {
148 148
             return (
149 149
                 $existingRecord->model_type == $this->model->getMorphClass() &&
150 150
                 $existingRecord->model_id == $this->model->id);
151
-        })->each(function($existingRecord){
151
+        })->each(function($existingRecord) {
152 152
 
153 153
             // TODO: if there is a redirect to this page, we'll take this one as the new url
154 154
             $existingRecord->delete();
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
      */
163 163
     private function prependBaseUrlSegment(string $slug, $locale): string
164 164
     {
165
-        $slugWithBaseSegment = $this->model->baseUrlSegment($locale) . '/' . $slug;
165
+        $slugWithBaseSegment = $this->model->baseUrlSegment($locale).'/'.$slug;
166 166
         $slugWithBaseSegment = trim($slugWithBaseSegment, '/');
167 167
 
168 168
         // If slug with base segment is empty string, it means that the passed slug was probably a "/" character.
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -140,7 +140,9 @@
 block discarded – undo
140 140
 
141 141
     private function deleteIdenticalRecords($existingRecords): void
142 142
     {
143
-        if($this->strict) return;
143
+        if($this->strict) {
144
+            return;
145
+        }
144 146
 
145 147
         // The old homepage url should be removed since this is no longer in effect.
146 148
         // In case of any redirect to this old homepage, the last used redirect is now back in effect.
Please login to merge, or discard this patch.
src/Urls/Application/RevertUrlSlug.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@  discard block
 block discarded – undo
23 23
 
24 24
     public function handle(string $locale): void
25 25
     {
26
-        try{
26
+        try {
27 27
             $currentUrlRecord = UrlRecord::findByModel($this->model, $locale);
28 28
 
29
-            if($recentRedirect = UrlRecord::findRecentRedirect($this->model, $locale)){
29
+            if ($recentRedirect = UrlRecord::findRecentRedirect($this->model, $locale)) {
30 30
 
31 31
                 $recentRedirectSlug = $recentRedirect->slug;
32 32
                 $recentRedirect->delete();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
                 $currentUrlRecord->replaceAndRedirect(['slug' => $recentRedirectSlug]);
35 35
             }
36 36
         }
37
-        catch(UrlRecordNotFound $e)
37
+        catch (UrlRecordNotFound $e)
38 38
         {
39 39
             // No url present so nothing to do here...
40 40
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,8 +33,7 @@
 block discarded – undo
33 33
 
34 34
                 $currentUrlRecord->replaceAndRedirect(['slug' => $recentRedirectSlug]);
35 35
             }
36
-        }
37
-        catch(UrlRecordNotFound $e)
36
+        } catch(UrlRecordNotFound $e)
38 37
         {
39 38
             // No url present so nothing to do here...
40 39
         }
Please login to merge, or discard this patch.
src/Urls/UrlHelper.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
      */
16 16
     public static function allOnlineModels(bool $onlySingles = false): array
17 17
     {
18
-        return chiefMemoize('all-online-models', function () use($onlySingles) {
18
+        return chiefMemoize('all-online-models', function() use($onlySingles) {
19 19
 
20 20
             $builder = UrlRecord::whereNull('redirect_id')->select('model_type', 'model_id')->groupBy('model_type', 'model_id');
21 21
 
22
-            if($onlySingles) {
22
+            if ($onlySingles) {
23 23
                 $builder->where('model_type', 'singles');
24 24
             }
25 25
 
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
             });
29 29
 
30 30
             // Get model for each of these records...
31
-            $models = $liveUrlRecords->map(function($record, $key){
31
+            $models = $liveUrlRecords->map(function($record, $key) {
32 32
                 return Morphables::instance($key)->find($record->toArray());
33
-            })->each->reject(function ($model) {
33
+            })->each->reject(function($model) {
34 34
                 // Invalid references to archived or removed models where url record still exists.
35 35
                 return is_null($model);
36 36
             })->flatten();
Please login to merge, or discard this patch.