@@ -63,11 +63,11 @@ |
||
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 | /** |
@@ -80,11 +80,11 @@ discard block |
||
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 |
||
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 ''; |
@@ -35,8 +35,8 @@ |
||
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; |
@@ -36,7 +36,9 @@ |
||
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; |
@@ -1,6 +1,6 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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]; |
@@ -22,7 +22,7 @@ |
||
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; |
@@ -22,7 +22,9 @@ |
||
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; |
@@ -65,8 +65,8 @@ discard block |
||
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 |
||
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 |
@@ -74,7 +74,7 @@ discard block |
||
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 |
||
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()) |
@@ -56,7 +56,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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. |
@@ -140,7 +140,9 @@ |
||
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. |
@@ -23,10 +23,10 @@ discard block |
||
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 |
||
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 | } |
@@ -33,8 +33,7 @@ |
||
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 | } |
@@ -15,11 +15,11 @@ discard block |
||
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 |
||
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(); |