1 | <?php |
||||||
2 | |||||||
3 | |||||||
4 | namespace Riclep\Storyblok\Traits; |
||||||
5 | |||||||
6 | |||||||
7 | use Riclep\Storyblok\Page; |
||||||
8 | |||||||
9 | trait SchemaOrg |
||||||
10 | { |
||||||
11 | /** |
||||||
12 | * Automatically called to add a schema to the Page |
||||||
13 | */ |
||||||
14 | protected function initSchemaOrg(): void |
||||||
15 | { |
||||||
16 | if (method_exists($this, 'schemaOrg')) { |
||||||
17 | if ($this instanceof Page) { |
||||||
18 | $page = $this; |
||||||
19 | } else { |
||||||
20 | $page = $this->page(); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
21 | } |
||||||
22 | |||||||
23 | if ($page) { |
||||||
24 | $this->add($page); |
||||||
25 | } |
||||||
26 | } |
||||||
27 | |||||||
28 | } |
||||||
29 | |||||||
30 | /** |
||||||
31 | * Returns the JavaScript JSON-LD string |
||||||
32 | * |
||||||
33 | * @return string |
||||||
34 | */ |
||||||
35 | public function schemaOrgScript(): string |
||||||
36 | { |
||||||
37 | $schemaJson = ''; |
||||||
38 | |||||||
39 | foreach ($this->meta()['schema_org'] as $schema) { |
||||||
0 ignored issues
–
show
It seems like
meta() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
40 | $schemaJson .= $schema->toScript(); |
||||||
41 | } |
||||||
42 | |||||||
43 | return $schemaJson; |
||||||
44 | } |
||||||
45 | |||||||
46 | /** |
||||||
47 | * Adds the schema to the meta of the current page |
||||||
48 | * |
||||||
49 | * @param $page |
||||||
50 | */ |
||||||
51 | private function add($page): void |
||||||
52 | { |
||||||
53 | $currentSchemaOrg = $page->meta('schema_org'); |
||||||
54 | |||||||
55 | $currentSchemaOrg[] = $this->schemaOrg(); |
||||||
0 ignored issues
–
show
The method
schemaOrg() does not exist on Riclep\Storyblok\Traits\SchemaOrg . Did you maybe mean schemaOrgScript() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
56 | |||||||
57 | $page->replaceMeta('schema_org', $currentSchemaOrg ?? []); |
||||||
58 | } |
||||||
59 | } |