Jsonld   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 25
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getJsonld() 0 23 2
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopsfaq\Common;
4
5
use XoopsModules\Xoopsfaq\{
6
    Contents,
7
    ContentsHandler
8
};
9
10
class Jsonld
11
{
12
    public static function getJsonld(?array $data, $settings = null): string
0 ignored issues
show
Unused Code introduced by
The parameter $settings is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

12
    public static function getJsonld(?array $data, /** @scrutinizer ignore-unused */ $settings = null): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
13
    {
14
        $out    = '';
15
        $jsonld = [];
16
        $schema = [];
17
18
        foreach ($data as $key => $value) {
19
            $schema['@context']   = 'https://schema.org/';
20
            $schema['@type']      = 'FAQPage';
21
            $schema['mainEntity'] = [
22
                '@type'          => 'Question',
23
                'name'           => $value['title'],
24
                'acceptedAnswer' => [
25
                    '@type' => 'Answer',
26
                    'text'  => $value['answer'],
27
                ],
28
            ];
29
            $jsonld[]             = $schema;
30
        }
31
32
        $out .= '<script type="application/ld+json">' . json_encode($jsonld, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES) . '</script>';
33
34
        return $out;
35
    }
36
}
37