Conditions | 9 |
Paths | 8 |
Total Lines | 28 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 90 |
Changes | 0 |
1 | <?php |
||
15 | public function filterSchema($data): array |
||
16 | { |
||
17 | $data = Arr::consolidate($data); |
||
18 | $schema = glsr(Schema::class)->generate(); |
||
19 | if (empty($schema)) { |
||
20 | return $data; |
||
21 | } |
||
22 | $allowedTypes = glsr(RatingSchemaTypeDefaults::class)->defaults(); |
||
23 | $aggregateRatingSchema = Arr::get($schema, 'aggregateRating'); |
||
24 | $reviewSchema = Arr::get($schema, 'review'); |
||
25 | foreach ($data as $key => $values) { |
||
26 | if ('richSnippet' !== $key |
||
27 | && !str_starts_with($key, 'new-') // used in preview |
||
28 | && !str_starts_with($key, 'schema-')) { |
||
29 | continue; |
||
30 | } |
||
31 | $type = $values['@type'] ?? ''; |
||
32 | if (!in_array($type, $allowedTypes)) { |
||
33 | continue; |
||
34 | } |
||
35 | if ($aggregateRatingSchema) { |
||
36 | $data[$key]['aggregateRating'] = $aggregateRatingSchema; |
||
37 | } |
||
38 | if ($reviewSchema) { |
||
39 | $data[$key]['review'] = $reviewSchema; |
||
40 | } |
||
41 | } |
||
42 | return $data; |
||
43 | } |
||
45 |