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

OpenGraphElement   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 8
c 4
b 0
f 0
dl 0
loc 24
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A uniqueKey() 0 3 1
A __construct() 0 4 1
A normalizeProperty() 0 3 2
A __toString() 0 3 1
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