@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | $data['country'] = Locale::getCountry($locale->code); |
| 52 | 52 | $data['locale'] = Locale::getLocale($locale->code); |
| 53 | 53 | |
| 54 | - if (! isset($data['payload'])) { |
|
| 54 | + if (!isset($data['payload'])) { |
|
| 55 | 55 | $data['payload'] = $this->mapPayload($entry, $locale->code); |
| 56 | 56 | } |
| 57 | - if (! isset($data['relationships'])) { |
|
| 57 | + if (!isset($data['relationships'])) { |
|
| 58 | 58 | $data['relationships'] = $this->mapRelationships($data['payload']); |
| 59 | 59 | } |
| 60 | 60 | if (isset($data['slug']) && Str::contains($data['slug'], 'untitled-')) { |
@@ -84,16 +84,16 @@ discard block |
||
| 84 | 84 | $dontFallback = config('contentful.payload_fields_not_fallback', []); |
| 85 | 85 | |
| 86 | 86 | $fallbackLocale = Locale::fallback($locale); |
| 87 | - $fallbackSecondLevel = ! empty($fallbackLocale) ? Locale::fallback($fallbackLocale) : null; |
|
| 87 | + $fallbackSecondLevel = !empty($fallbackLocale) ? Locale::fallback($fallbackLocale) : null; |
|
| 88 | 88 | |
| 89 | 89 | foreach ($entry['fields'] as $field => $localesData) { |
| 90 | 90 | if (isset($localesData[$locale])) { |
| 91 | 91 | $payload[$field] = $localesData[$locale]; |
| 92 | 92 | } else { |
| 93 | - if (! in_array($field, $dontFallback) && isset($localesData[$fallbackLocale]) && ($this->levelFallBack($field) === 'all')) { |
|
| 93 | + if (!in_array($field, $dontFallback) && isset($localesData[$fallbackLocale]) && ($this->levelFallBack($field) === 'all')) { |
|
| 94 | 94 | $payload[$field] = $localesData[$fallbackLocale]; |
| 95 | 95 | } else { |
| 96 | - if (! empty($fallbackSecondLevel) && ! in_array($field, $dontFallback) && isset($localesData[$fallbackSecondLevel]) && ($this->levelFallBack($field) === 'all')) { |
|
| 96 | + if (!empty($fallbackSecondLevel) && !in_array($field, $dontFallback) && isset($localesData[$fallbackSecondLevel]) && ($this->levelFallBack($field) === 'all')) { |
|
| 97 | 97 | $payload[$field] = $localesData[$fallbackSecondLevel]; |
| 98 | 98 | } else { |
| 99 | 99 | $payload[$field] = null; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - throw new Exception('Invalid field signature... ' . PHP_EOL . print_r($localeField, true)); |
|
| 187 | + throw new Exception('Invalid field signature... '.PHP_EOL.print_r($localeField, true)); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | 'content_type' => 'single_entry', |
| 221 | 221 | ]); |
| 222 | 222 | |
| 223 | - if (! empty($entry) && ! empty($entry['sys']['contentType']) && ! empty($entry['sys']['contentType']['sys'])) { |
|
| 223 | + if (!empty($entry) && !empty($entry['sys']['contentType']) && !empty($entry['sys']['contentType']['sys'])) { |
|
| 224 | 224 | $this->upsertEntryType($entry, $entry['sys']['contentType']['sys']['id']); |
| 225 | 225 | |
| 226 | 226 | return $entry['sys']['contentType']['sys']['id']; |
| 227 | 227 | } |
| 228 | 228 | } catch (Exception $e) { |
| 229 | - throw new Exception('Unknown content-type from synced entry: ' . $contentfulId); |
|
| 229 | + throw new Exception('Unknown content-type from synced entry: '.$contentfulId); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | { |
| 248 | 248 | $locales = []; |
| 249 | 249 | |
| 250 | - if (isset($entry['fields']) && ! empty($entry['fields'])) { |
|
| 250 | + if (isset($entry['fields']) && !empty($entry['fields'])) { |
|
| 251 | 251 | $firstField = Arr::first($entry['fields']); |
| 252 | 252 | $locales = array_keys($firstField); |
| 253 | 253 | } |
@@ -19,10 +19,10 @@ discard block |
||
| 19 | 19 | public function apply(Builder $builder, Model $model) |
| 20 | 20 | { |
| 21 | 21 | $builder |
| 22 | - ->where(function ($query) use ($model) { |
|
| 22 | + ->where(function($query) use ($model) { |
|
| 23 | 23 | $query |
| 24 | - ->whereNull($model->getTable() . '.validated_at') |
|
| 25 | - ->orWhere($model->getTable() . '.validated_at', '>=', Carbon::now()->format('Y-m-d H:i:s')); |
|
| 24 | + ->whereNull($model->getTable().'.validated_at') |
|
| 25 | + ->orWhere($model->getTable().'.validated_at', '>=', Carbon::now()->format('Y-m-d H:i:s')); |
|
| 26 | 26 | }); |
| 27 | 27 | |
| 28 | 28 | $this->extend($builder); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function extend(Builder $builder) |
| 38 | 38 | { |
| 39 | - $builder->macro('withoutValidated', function (Builder $builder) { |
|
| 39 | + $builder->macro('withoutValidated', function(Builder $builder) { |
|
| 40 | 40 | return $builder->withoutGlobalScope($this); |
| 41 | 41 | }); |
| 42 | 42 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | public function handle(string $action, array $payload, bool $isPreview) |
| 37 | 37 | { |
| 38 | 38 | $actionMethods = ['create', 'archive', 'unarchive', 'publish', 'unpublish', 'delete']; |
| 39 | - $actionMethods = ! empty($isPreview) ? array_merge($actionMethods, ['save', 'auto_save']): $actionMethods; |
|
| 39 | + $actionMethods = !empty($isPreview) ? array_merge($actionMethods, ['save', 'auto_save']) : $actionMethods; |
|
| 40 | 40 | |
| 41 | 41 | if (method_exists($this, $action) && in_array($action, $actionMethods)) { |
| 42 | 42 | $this->$action($payload); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | $locales = []; |
| 62 | 62 | |
| 63 | - if (isset($asset['fields']) && ! empty($asset['fields'])) { |
|
| 63 | + if (isset($asset['fields']) && !empty($asset['fields'])) { |
|
| 64 | 64 | $firstField = Arr::first($asset['fields']); |
| 65 | 65 | $locales = array_keys($firstField); |
| 66 | 66 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $country = Locale::getCountry($locale); |
| 81 | 81 | $iso = Locale::getLocale($locale); |
| 82 | 82 | |
| 83 | - if (! Locale::canBeSave($country, $iso)) { |
|
| 83 | + if (!Locale::canBeSave($country, $iso)) { |
|
| 84 | 84 | return null; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -165,11 +165,9 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | protected function getFieldValue(array $fields, string $field, string $locale, string $fallbackLocale, $default, string $secondFallback = null) |
| 167 | 167 | { |
| 168 | - return ! empty($fields[$field][$locale]) ? |
|
| 169 | - $fields[$field][$locale] : |
|
| 170 | - ( |
|
| 171 | - ! empty($fields[$field][$fallbackLocale]) ? $fields[$field][$fallbackLocale] : |
|
| 172 | - (! empty($secondFallback) && ! empty($fields[$field][$secondFallback]) ? $fields[$field][$secondFallback] : $default) |
|
| 168 | + return !empty($fields[$field][$locale]) ? |
|
| 169 | + $fields[$field][$locale] : ( |
|
| 170 | + !empty($fields[$field][$fallbackLocale]) ? $fields[$field][$fallbackLocale] : (!empty($secondFallback) && !empty($fields[$field][$secondFallback]) ? $fields[$field][$secondFallback] : $default) |
|
| 173 | 171 | ); |
| 174 | 172 | } |
| 175 | 173 | } |
@@ -25,14 +25,14 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | $modelPath = config('contentful.generator.model'); |
| 27 | 27 | |
| 28 | - foreach (glob($modelPath . '/*.php') as $file) { |
|
| 28 | + foreach (glob($modelPath.'/*.php') as $file) { |
|
| 29 | 29 | $modelInstance = NamespaceResolver::model(str_replace( |
| 30 | 30 | [$modelPath, '.php', '/'], |
| 31 | 31 | ['', '', '\\'], |
| 32 | 32 | $file |
| 33 | 33 | )); |
| 34 | 34 | |
| 35 | - if (! empty($modelInstance) && $modelInstance instanceof ContentfulModel) { |
|
| 35 | + if (!empty($modelInstance) && $modelInstance instanceof ContentfulModel) { |
|
| 36 | 36 | $modelInstance->query()->truncate(); |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | foreach ($localeEntries as $localeEntry) { |
| 59 | 59 | $model = $this->upsertLocale($entry, $localeEntry); |
| 60 | 60 | |
| 61 | - if (! empty($model)) { |
|
| 61 | + if (!empty($model)) { |
|
| 62 | 62 | if (isset($localeEntry['relationships'])) { |
| 63 | 63 | $this->handleRelationships($localeEntry['locale'], $localeEntry['country'], $localeEntry['contentful_id'], $this->entryContentType($entry), $localeEntry['relationships']); |
| 64 | 64 | unset($localeEntry['relationships']); |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | private function entryMapper(array $entry): ContentfulMapper |
| 112 | 112 | { |
| 113 | - $class = Str::studly($this->entryContentType($entry)) . 'Mapper'; |
|
| 113 | + $class = Str::studly($this->entryContentType($entry)).'Mapper'; |
|
| 114 | 114 | $mapperClass = NamespaceResolver::mapper($class); |
| 115 | 115 | |
| 116 | - if (empty($mapperClass) && ! ($mapperClass instanceof ContentfulMapper)) { |
|
| 117 | - throw new Exception('Unknown mapper: ' . $class); |
|
| 116 | + if (empty($mapperClass) && !($mapperClass instanceof ContentfulMapper)) { |
|
| 117 | + throw new Exception('Unknown mapper: '.$class); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | return new $mapperClass; |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $modelClass = NamespaceResolver::modelClass($model); |
| 134 | 134 | |
| 135 | 135 | if (empty($modelClass)) { |
| 136 | - throw new Exception('Unknown model: ' . $model); |
|
| 136 | + throw new Exception('Unknown model: '.$model); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return new $modelClass; |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | $order = 1; |
| 166 | 166 | foreach ($relationships as $relationship) { |
| 167 | - if (! isset($relationship['id']) || ! isset($relationship['type'])) { |
|
| 168 | - throw new Exception('Relationships malformed! (' . print_r($relationship, true) . ')'); |
|
| 167 | + if (!isset($relationship['id']) || !isset($relationship['type'])) { |
|
| 168 | + throw new Exception('Relationships malformed! ('.print_r($relationship, true).')'); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | DB::table('entry_relationships')->insert([ |
@@ -212,18 +212,18 @@ discard block |
||
| 212 | 212 | private function upsertLocale(array $entry, array $data): ?ContentfulModel |
| 213 | 213 | { |
| 214 | 214 | $model = $this->entryModel($entry); |
| 215 | - if ((method_exists($model, 'bootNotNullSlug') && empty($data['slug'])) || ! Locale::canBeSave($data['country'], $data['locale'])) { |
|
| 215 | + if ((method_exists($model, 'bootNotNullSlug') && empty($data['slug'])) || !Locale::canBeSave($data['country'], $data['locale'])) { |
|
| 216 | 216 | // Remove instance if slug is empty |
| 217 | 217 | $instance = $this->instanceQueryBuilder($model, $data)->first(); |
| 218 | - if (! empty($instance)) { |
|
| 218 | + if (!empty($instance)) { |
|
| 219 | 219 | $instance->delete(); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | return null; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - if (! isset($data['payload'])) { |
|
| 226 | - throw new Exception('Mapper for model ' . class_basename($model) . ' must set a "payload" key'); |
|
| 225 | + if (!isset($data['payload'])) { |
|
| 226 | + throw new Exception('Mapper for model '.class_basename($model).' must set a "payload" key'); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | $instance = $this->instanceQueryBuilder($model, $data)->first(); |
@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | protected function dumpSync(bool $isPreview, string $connector = 'mysql'): string |
| 31 | 31 | { |
| 32 | - $path = storage_path('dumps/' . date('YmdHis') . '_sync' . ($isPreview ? '_preview' : '') . '.sql'); |
|
| 33 | - $this->warn('Dump "' . basename($path) . '"...'); |
|
| 32 | + $path = storage_path('dumps/'.date('YmdHis').'_sync'.($isPreview ? '_preview' : '').'.sql'); |
|
| 33 | + $this->warn('Dump "'.basename($path).'"...'); |
|
| 34 | 34 | |
| 35 | 35 | $dirName = dirname($path); |
| 36 | - if (! is_dir($dirName)) { |
|
| 36 | + if (!is_dir($dirName)) { |
|
| 37 | 37 | mkdir($dirName, 0777, true); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | $command = sprintf( |
| 57 | 57 | $exec, |
| 58 | - addcslashes(config('database.connections.' . $connector . '.password'), "'"), |
|
| 59 | - config('database.connections.' . $connector . '.charset'), |
|
| 60 | - config('database.connections.' . $connector . '.database'), |
|
| 61 | - config('database.connections.' . $connector . '.username'), |
|
| 62 | - config('database.connections.' . $connector . '.host'), |
|
| 63 | - config('database.connections.' . $connector . '.port'), |
|
| 58 | + addcslashes(config('database.connections.'.$connector.'.password'), "'"), |
|
| 59 | + config('database.connections.'.$connector.'.charset'), |
|
| 60 | + config('database.connections.'.$connector.'.database'), |
|
| 61 | + config('database.connections.'.$connector.'.username'), |
|
| 62 | + config('database.connections.'.$connector.'.host'), |
|
| 63 | + config('database.connections.'.$connector.'.port'), |
|
| 64 | 64 | $path |
| 65 | 65 | ); |
| 66 | 66 | exec($command); |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | protected function getConnector(bool $isPreview, string $connector = 'mysql'): string |
| 70 | 70 | { |
| 71 | - $compiledConnector = $connector . ($isPreview ? '_preview' : ''); |
|
| 71 | + $compiledConnector = $connector.($isPreview ? '_preview' : ''); |
|
| 72 | 72 | |
| 73 | - if (empty(config('database.connections.' . $compiledConnector . '.username'))) { |
|
| 73 | + if (empty(config('database.connections.'.$compiledConnector.'.username'))) { |
|
| 74 | 74 | $compiledConnector = $connector; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | 'database.default' => $compiledConnector, |
| 94 | 94 | ]); |
| 95 | 95 | |
| 96 | - $this->warn('Put into "' . $compiledConnector . '" database...'); |
|
| 96 | + $this->warn('Put into "'.$compiledConnector.'" database...'); |
|
| 97 | 97 | $this->putSql($path, $compiledConnector); |
| 98 | 98 | } |
| 99 | 99 | |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $command = sprintf( |
| 112 | 112 | $exec, |
| 113 | - addcslashes(config('database.connections.' . $connector . '.password'), "'"), |
|
| 114 | - config('database.connections.' . $connector . '.username'), |
|
| 115 | - config('database.connections.' . $connector . '.host'), |
|
| 116 | - config('database.connections.' . $connector . '.port'), |
|
| 117 | - config('database.connections.' . $connector . '.database'), |
|
| 113 | + addcslashes(config('database.connections.'.$connector.'.password'), "'"), |
|
| 114 | + config('database.connections.'.$connector.'.username'), |
|
| 115 | + config('database.connections.'.$connector.'.host'), |
|
| 116 | + config('database.connections.'.$connector.'.port'), |
|
| 117 | + config('database.connections.'.$connector.'.database'), |
|
| 118 | 118 | $path |
| 119 | 119 | ); |
| 120 | 120 | |