1 | <?php |
||
12 | abstract class ContentfulMapper |
||
13 | { |
||
14 | /** |
||
15 | * Map entry specific payload. |
||
16 | * |
||
17 | * @param array $entry |
||
18 | * @param string $locale |
||
19 | * @return array |
||
20 | * @throws \Exception |
||
21 | */ |
||
22 | abstract protected function map(array $entry, string $locale): array; |
||
23 | |||
24 | /** |
||
25 | * Map entry with common data + specific payload for each locales. |
||
26 | * |
||
27 | * @param array $entry |
||
28 | * @return array |
||
29 | * @throws \Exception |
||
30 | */ |
||
31 | public function toLocaleEntries(array $entry, Collection $locales): array |
||
65 | |||
66 | // -------------------------------------------------------------------------------- |
||
67 | // -------------------------------------------------------------------------------- |
||
68 | // -------------------------------------------------------------------------------- |
||
69 | |||
70 | /** |
||
71 | * Return raw entry fields payload for given locale. |
||
72 | * |
||
73 | * @param array $entry |
||
74 | * @param string $locale |
||
75 | * @return array |
||
76 | */ |
||
77 | protected function mapPayload(array $entry, string $locale): array |
||
97 | |||
98 | |||
99 | protected function levelFallBack($field) |
||
105 | |||
106 | // -------------------------------------------------------------------------------- |
||
107 | // -------------------------------------------------------------------------------- |
||
108 | // -------------------------------------------------------------------------------- |
||
109 | |||
110 | /** |
||
111 | * Map relationships in given payload. |
||
112 | * |
||
113 | * @param array $payload |
||
114 | * @return array |
||
115 | * @throws \Exception |
||
116 | */ |
||
117 | protected function mapRelationships($payload): array |
||
139 | |||
140 | /** |
||
141 | * Return relationship signature for given "localized" field. |
||
142 | * |
||
143 | * @param array $localeField |
||
144 | * @return array|null |
||
145 | * @throws \Exception |
||
146 | */ |
||
147 | private function relationshipSignature($localeField): ?array |
||
163 | |||
164 | /** |
||
165 | * Return if field is a Link one. |
||
166 | * |
||
167 | * @param mixed $localeField |
||
168 | * @return bool |
||
169 | */ |
||
170 | private function isLink($localeField): bool |
||
174 | |||
175 | /** |
||
176 | * Return contentful-type for given Contentful ID from `sync_entries` table. |
||
177 | * |
||
178 | * @param string $contentfulId |
||
179 | * @return string |
||
180 | * @throws \Exception |
||
181 | */ |
||
182 | private function contentTypeFromSyncEntries(string $contentfulId): string |
||
195 | |||
196 | /** |
||
197 | * Return content-type for given Contentful ID from `entry_types` table. |
||
198 | * |
||
199 | * @param string $contentfulId |
||
200 | * @return string |
||
201 | * @throws \Exception |
||
202 | */ |
||
203 | private function contentTypeFromEntryTypes(string $contentfulId): string |
||
216 | |||
217 | // -------------------------------------------------------------------------------- |
||
218 | // -------------------------------------------------------------------------------- |
||
219 | // -------------------------------------------------------------------------------- |
||
220 | |||
221 | /** |
||
222 | * Return all locales in entry payload. |
||
223 | * |
||
224 | * @param array $entry |
||
225 | * @return array |
||
226 | */ |
||
227 | private function entryLocales(array $entry): array |
||
238 | } |
||
239 |
This check looks for the
else
branches ofif
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
else
branches can be removed.could be turned into
This is much more concise to read.