Meta::addKeywords()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Form\Factory\Page;
6
7
use AbterPhp\Framework\Form\Container\FormGroup;
8
use AbterPhp\Framework\Form\Element\Input;
9
use AbterPhp\Framework\Form\Element\Textarea;
10
use AbterPhp\Framework\Form\Extra\Help;
11
use AbterPhp\Framework\Form\Label\Countable;
12
use AbterPhp\Framework\Form\Label\Label;
13
use AbterPhp\Framework\Html\INode;
14
use AbterPhp\Website\Domain\Entities\Page as Entity;
15
16
class Meta
17
{
18
    /**
19
     * @return INode[]
20
     */
21
    public function create(Entity $entity): array
22
    {
23
        $components = [];
24
25
        $components[] = $this->addOGTitle($entity);
26
        $components[] = $this->addOGImage($entity);
27
        $components[] = $this->addOGDescription($entity);
28
        $components[] = $this->addAuthor($entity);
29
        $components[] = $this->addCopyright($entity);
30
        $components[] = $this->addKeywords($entity);
31
        $components[] = $this->addRobots($entity);
32
33
        return $components;
34
    }
35
36
    /**
37
     * @param Entity $entity
38
     *
39
     * @return INode
40
     */
41
    protected function addOGTitle(Entity $entity): INode
42
    {
43
        $input = new Input('og-title', 'og-title', $entity->getMeta()->getOGTitle());
44
        $label = new Label('og-title', 'website:pageOGTitle');
45
        $help  = new Help('website:pageOGTitleHelp');
46
47
        return new FormGroup($input, $label, $help);
48
    }
49
50
    /**
51
     * @param Entity $entity
52
     *
53
     * @return INode
54
     */
55
    protected function addOGImage(Entity $entity): INode
56
    {
57
        $input = new Input('og-image', 'og-image', $entity->getMeta()->getOGImage());
58
        $label = new Label('og-image', 'website:pageOGImage');
59
        $help  = new Help('website:pageOGImageHelp');
60
61
        return new FormGroup($input, $label, $help);
62
    }
63
64
    /**
65
     * @param Entity $entity
66
     *
67
     * @return INode
68
     */
69
    protected function addOGDescription(Entity $entity): INode
70
    {
71
        $input = new Textarea('og-description', 'og-description', $entity->getMeta()->getOGDescription());
72
        $label = new Countable(
73
            'og-description',
74
            'website:pageOGDescription',
75
            Countable::DEFAULT_SIZE
76
        );
77
        $help  = new Help('website:pageOGDescriptionHelp');
78
79
        return new FormGroup($input, $label, $help);
80
    }
81
82
    /**
83
     * @param Entity $entity
84
     *
85
     * @return INode
86
     */
87
    protected function addAuthor(Entity $entity): INode
88
    {
89
        $input = new Input('author', 'author', $entity->getMeta()->getAuthor());
90
        $label = new Label('author', 'website:pageAuthor');
91
        $help  = new Help('website:pageAuthor');
92
93
        return new FormGroup($input, $label, $help);
94
    }
95
96
    /**
97
     * @param Entity $entity
98
     *
99
     * @return INode
100
     */
101
    protected function addCopyright(Entity $entity): INode
102
    {
103
        $input = new Input('copyright', 'copyright', $entity->getMeta()->getAuthor());
104
        $label = new Label('copyright', 'website:pageCopyright');
105
        $help  = new Help('website:pageCopyrightHelp');
106
107
        return new FormGroup($input, $label, $help);
108
    }
109
110
    /**
111
     * @param Entity $entity
112
     *
113
     * @return INode
114
     */
115
    protected function addKeywords(Entity $entity): INode
116
    {
117
        $input = new Input('keywords', 'keywords', $entity->getMeta()->getKeywords());
118
        $label = new Label('keywords', 'website:pageKeywords');
119
        $help  = new Help('website:pageKeywordsHelp');
120
121
        return new FormGroup($input, $label, $help);
122
    }
123
124
    /**
125
     * @param Entity $entity
126
     *
127
     * @return INode
128
     */
129
    protected function addRobots(Entity $entity): INode
130
    {
131
        $input = new Input('robots', 'robots', $entity->getMeta()->getRobots());
132
        $label = new Label('robots', 'website:pageRobots');
133
        $help  = new Help('website:pageRobotsHelp');
134
135
        return new FormGroup($input, $label, $help);
136
    }
137
}
138