Passed
Push — master ( 80ddec...cae974 )
by Caen
03:33 queued 12s
created

OpenGraphItem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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