Passed
Pull Request — master (#11)
by Michael
11:08
created

Jsonld::getJsonld()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 23
rs 9.7666
1
<?php
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)
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)

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"]   = "http://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