Code Duplication    Length = 51-51 lines in 3 locations

src/Pageon/Html/Meta/Item/ItemPropMeta.php 1 location

@@ 7-57 (lines=51) @@
4
5
use Pageon\Html\Meta\MetaItem;
6
7
final class ItemPropMeta implements MetaItem
8
{
9
    /**
10
     * @var string
11
     */
12
    private $name;
13
14
    /**
15
     * @var string
16
     */
17
    private $content;
18
19
    /**
20
     * @param string $name
21
     * @param string $content
22
     *
23
     * @return MetaItem
24
     */
25
    public static function create(string $name, string $content) : MetaItem {
26
        return new self($name, $content);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function render(array $extra = []) : string {
33
        $content = $this->content;
34
35
        if ($this->isTitle() && isset($extra['title']['suffix'])) {
36
            $content = "{$content}{$extra['title']['suffix']}";
37
        }
38
39
        return "<meta itemprop=\"{$this->name}\" content=\"{$content}\">";
40
    }
41
42
    /**
43
     * NamedMeta constructor.
44
     *
45
     * @param string $name
46
     * @param string $content
47
     */
48
    public function __construct(string $name, string $content) {
49
        $this->name = $name;
50
        $this->content = htmlentities($content);
51
    }
52
53
    private function isTitle(): bool
54
    {
55
        return str_contains($this->name, 'title') || $this->name === 'name';
56
    }
57
}
58

src/Pageon/Html/Meta/Item/NameMeta.php 1 location

@@ 7-57 (lines=51) @@
4
5
use Pageon\Html\Meta\MetaItem;
6
7
final class NameMeta implements MetaItem
8
{
9
    /**
10
     * @var string
11
     */
12
    private $name;
13
14
    /**
15
     * @var string
16
     */
17
    private $content;
18
19
    /**
20
     * @param string $name
21
     * @param string $content
22
     *
23
     * @return MetaItem
24
     */
25
    public static function create(string $name, string $content) : MetaItem {
26
        return new self($name, $content);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function render(array $extra = []) : string {
33
        $content = $this->content;
34
35
        if ($this->isTitle() && isset($extra['title']['suffix'])) {
36
            $content = "{$content}{$extra['title']['suffix']}";
37
        }
38
39
        return "<meta name=\"{$this->name}\" content=\"{$content}\">";
40
    }
41
42
    /**
43
     * NamedMeta constructor.
44
     *
45
     * @param string $name
46
     * @param string $content
47
     */
48
    public function __construct(string $name, string $content) {
49
        $this->name = $name;
50
        $this->content = htmlentities($content);
51
    }
52
53
    private function isTitle(): bool
54
    {
55
        return str_contains($this->name, 'title');
56
    }
57
}
58

src/Pageon/Html/Meta/Item/PropertyMeta.php 1 location

@@ 7-57 (lines=51) @@
4
5
use Pageon\Html\Meta\MetaItem;
6
7
final class PropertyMeta implements MetaItem
8
{
9
    /**
10
     * @var string
11
     */
12
    private $name;
13
14
    /**
15
     * @var string
16
     */
17
    private $content;
18
19
    /**
20
     * @param string $property
21
     * @param string $content
22
     *
23
     * @return MetaItem
24
     */
25
    public static function create(string $property, string $content) : MetaItem {
26
        return new self($property, $content);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function render(array $extra = []) : string {
33
        $content = $this->content;
34
35
        if ($this->isTitle() && isset($extra['title']['suffix'])) {
36
            $content = "{$content}{$extra['title']['suffix']}";
37
        }
38
39
        return "<meta property=\"{$this->name}\" content=\"{$content}\">";
40
    }
41
42
    /**
43
     * NamedMeta constructor.
44
     *
45
     * @param string $name
46
     * @param string $content
47
     */
48
    public function __construct(string $name, string $content) {
49
        $this->name = $name;
50
        $this->content = htmlentities($content);
51
    }
52
53
    private function isTitle(): bool
54
    {
55
        return str_contains($this->name, 'title');
56
    }
57
}
58