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

HasStructuredData   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 17
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A toJsonLdScript() 0 3 1
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