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

OpenGraphItem   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 5

4 Methods

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