Passed
Push — master ( 5399ee...fe113d )
by Caen
03:32 queued 12s
created

Meta   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 61
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A get() 0 3 1
A render() 0 3 1
A property() 0 3 1
A link() 0 3 1
1
<?php
2
3
namespace Hyde\Framework\Helpers;
4
5
use Hyde\Framework\Modules\Metadata\GlobalMetadataBag;
6
use Hyde\Framework\Modules\Metadata\Models\LinkElement;
7
use Hyde\Framework\Modules\Metadata\Models\MetadataElement;
8
use Hyde\Framework\Modules\Metadata\Models\OpenGraphElement;
9
10
/**
11
 * Helpers to fluently declare HTML meta elements using their object representations.
12
 *
13
 * @see \Hyde\Framework\Testing\Feature\MetadataHelperTest
14
 */
15
class Meta
16
{
17
    /**
18
     * Create a new <meta> element class with the given name and content.
19
     *
20
     * @param  string  $name  The meta tag's name attribute.
21
     * @param  string  $content  The content of the meta tag.
22
     * @return \Hyde\Framework\Modules\Metadata\Models\MetadataElement
23
     *
24
     * @link https://www.w3schools.com/tags/tag_meta.asp
25
     */
26
    public static function name(string $name, string $content): MetadataElement
27
    {
28
        return new MetadataElement($name, $content);
29
    }
30
31
    /**
32
     * Create a new <meta> element class with the given OpenGraph property and content.
33
     *
34
     * @param  string  $property  The meta tag's property attribute. The "og:" prefix is optional.
35
     * @param  string  $content  The content of the meta tag.
36
     * @return \Hyde\Framework\Modules\Metadata\Models\OpenGraphElement
37
     *
38
     * @link https://ogp.me/
39
     */
40
    public static function property(string $property, string $content): OpenGraphElement
41
    {
42
        return new OpenGraphElement($property, $content);
43
    }
44
45
    /**
46
     * Create a new <link> element class with the given rel and href.
47
     *
48
     * @param  string  $rel  The link tag's rel attribute.
49
     * @param  string  $href  The link tag's href attribute.
50
     * @param  array  $attr  An optional key-value array of additional attributes.
51
     * @return \Hyde\Framework\Modules\Metadata\Models\LinkElement
52
     *
53
     * @link https://www.w3schools.com/tags/tag_link.asp
54
     */
55
    public static function link(string $rel, string $href, array $attr = []): LinkElement
56
    {
57
        return new LinkElement($rel, $href, $attr);
58
    }
59
60
    /**
61
     * Get the global metadata bag.
62
     */
63
    public static function get(): GlobalMetadataBag
64
    {
65
        return GlobalMetadataBag::make();
66
    }
67
68
    /**
69
     * Render the global metadata bag.
70
     *
71
     * @return string
72
     */
73
    public static function render(): string
74
    {
75
        return static::get()->render();
76
    }
77
}
78