Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
OpenGraphElement | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
__toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
uniqueKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
normalizeProperty | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Hyde\Framework\Features\Metadata\Elements; |
6 | |
7 | use Hyde\Framework\Features\Metadata\MetadataElementContract; |
8 | |
9 | use function sprintf; |
10 | use function str_starts_with; |
11 | use function substr; |
12 | use function e; |
13 | |
14 | class OpenGraphElement implements MetadataElementContract |
15 | { |
16 | protected string $property; |
17 | protected string $content; |
18 | |
19 | public function __construct(string $property, string $content) |
20 | { |
21 | $this->property = $this->normalizeProperty($property); |
22 | $this->content = $content; |
23 | } |
24 | |
25 | public function __toString(): string |
26 | { |
27 | return sprintf('<meta property="og:%s" content="%s">', e($this->property), e($this->content)); |
28 | } |
29 | |
30 | public function uniqueKey(): string |
31 | { |
32 | return $this->property; |
33 | } |
34 | |
35 | protected function normalizeProperty(string $property): string |
36 | { |
37 | return str_starts_with($property, 'og:') ? substr($property, 3) : $property; |
38 | } |
39 | } |