Passed
Push — master ( 9e7cad...7929d2 )
by Caen
03:29 queued 12s
created

OpenGraphElement::normalizeProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Hyde\Framework\Modules\Metadata\Models;
4
5
class OpenGraphElement extends BaseMetadataElement
6
{
7
    protected string $property;
8
    protected string $content;
9
10
    public function __construct(string $property, string $content)
11
    {
12
        $this->property = $this->normalizeProperty($property);
13
        $this->content = $content;
14
    }
15
16
    public function __toString(): string
17
    {
18
        return sprintf('<meta property="og:%s" content="%s">', e($this->property), e($this->content));
19
    }
20
21
    public function uniqueKey(): string
22
    {
23
        return $this->property;
24
    }
25
26
    protected function normalizeProperty(string $property): string
27
    {
28
        return str_starts_with($property, 'og:') ? substr($property, 3) : $property;
29
    }
30
}
31