| Conditions | 6 |
| Paths | 7 |
| Total Lines | 23 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| 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 | $type = $values['@type'] ?? ''; |
||
| 27 | if (!in_array($type, $allowedTypes)) { |
||
| 28 | continue; |
||
| 29 | } |
||
| 30 | if ($aggregateRatingSchema) { |
||
| 31 | $data[$key]['aggregateRating'] = $aggregateRatingSchema; |
||
| 32 | } |
||
| 33 | if ($reviewSchema) { |
||
| 34 | $data[$key]['review'] = $reviewSchema; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | return $data; |
||
| 38 | } |
||
| 40 |