Test Setup Failed
Pull Request — main (#28)
by Enrico
07:55
created

HasStructuredData::toJsonLdScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace App\Traits;
5
6
7
use Spatie\SchemaOrg\Type;
8
9
/**
10
 * Trait HasStructuredData to implement a builder for all Schema.org types
11
 * and their properties using the spatie/schema-org package.
12
 *
13
 * @see https://schema.org
14
 * @see https://github.com/spatie/schema-org
15
 *
16
 * @package App\Traits
17
 */
18
trait HasStructuredData
19
{
20
    /**
21
     * Factory method for generating the script for a Schema.org type.
22
     *
23
     * @return Type
24
     */
25
    abstract protected function generateStructuredDataScript() : Type;
26
27
    /**
28
     * Render a json-ld script tag for the entity that implements this trait.
29
     *
30
     * @return string
31
     */
32
    public function toJsonLdScript() : string
33
    {
34
        return $this->generateStructuredDataScript()->toScript();
35
    }
36
}
37