Test Failed
Push — develop ( 2ae3c1...31453c )
by Paul
13:05
created

Controller::filterSchema()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 25
rs 9.0444
ccs 0
cts 17
cp 0
cc 6
nc 10
nop 1
crap 42
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\SASWP;
4
5
use GeminiLabs\SiteReviews\Controllers\AbstractController;
6
use GeminiLabs\SiteReviews\Helpers\Arr;
7
use GeminiLabs\SiteReviews\Modules\Schema;
8
9
class Controller extends AbstractController
10
{
11
    /**
12
     * @param array $data
13
     *
14
     * @filter saswp_modify_reviews_schema
15
     */
16
    public function filterSchema($data): array
17
    {
18
        $data = Arr::consolidate($data);
19
        $schema = glsr(Schema::class)->generate();
20
        if (empty($schema)) {
21
            return $data;
22
        }
23
        $aggregateRatingSchema = Arr::get($schema, 'aggregateRating');
24
        $reviewSchema = Arr::get($schema, 'review');
25
        $isReviewType = in_array(Arr::get($data, '@type'), ['Review', 'ReviewNewsArticle']);
26
        if (!empty($aggregateRatingSchema)) {
27
            if ($isReviewType) {
28
                $data['itemReviewed']['aggregateRating'] = $aggregateRatingSchema;
29
            } else {
30
                $data['aggregateRating'] = $aggregateRatingSchema;
31
            }
32
        }
33
        if (!empty($reviewSchema)) {
34
            if ($isReviewType) {
35
                $data['itemReviewed']['review'] = $reviewSchema;
36
            } else {
37
                $data['review'] = $reviewSchema;
38
            }
39
        }
40
        return $data;
41
    }
42
}
43