Passed
Push — master ( 26f223...98f436 )
by Peter
03:08
created

Advanced   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 59
c 1
b 0
f 0
dl 0
loc 146
rs 10
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A addClasses() 0 7 1
A addWithImage() 0 17 2
A addWithLinks() 0 17 2
A __construct() 0 3 1
A addProtected() 0 17 2
A addWithHtml() 0 17 2
A create() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Form\Factory\ContentList;
6
7
use AbterPhp\Framework\Constant\Html5;
8
use AbterPhp\Framework\Form\Container\CheckboxGroup;
9
use AbterPhp\Framework\Form\Container\FormGroup;
10
use AbterPhp\Framework\Form\Element\Input;
11
use AbterPhp\Framework\Form\Extra\Help;
12
use AbterPhp\Framework\Form\Label\Label;
13
use AbterPhp\Framework\Html\INode;
14
use AbterPhp\Framework\I18n\ITranslator;
15
use AbterPhp\Website\Domain\Entities\ContentList as Entity;
16
17
class Advanced
18
{
19
    /** @var ITranslator */
20
    protected $translator;
21
22
    /** @var array */
23
    protected $hiddenAttribs = [Html5::ATTR_TYPE => Input::TYPE_HIDDEN];
24
25
    /**
26
     * Hideable constructor.
27
     *
28
     * @param ITranslator $translator
29
     */
30
    public function __construct(ITranslator $translator)
31
    {
32
        $this->translator = $translator;
33
    }
34
35
    /**
36
     * @param Entity $entity
37
     *
38
     * @return INode[]
39
     */
40
    public function create(Entity $entity): array
41
    {
42
        $components = [];
43
44
        $components[] = $this->addClasses($entity);
45
        $components[] = $this->addProtected($entity);
46
        $components[] = $this->addWithImage($entity);
47
        $components[] = $this->addWithLinks($entity);
48
        $components[] = $this->addWithHtml($entity);
49
50
        return $components;
51
    }
52
53
    /**
54
     * @param Entity $entity
55
     *
56
     * @return INode
57
     */
58
    protected function addClasses(Entity $entity): INode
59
    {
60
        $input = new Input('classes', 'classes', $entity->getClasses());
61
        $label = new Label('classes', 'website:contentListClasses');
62
        $help  = new Help('website:contentListClassesHelp');
63
64
        return new FormGroup($input, $label, $help);
65
    }
66
67
    /**
68
     * @param Entity $entity
69
     *
70
     * @return INode
71
     */
72
    protected function addProtected(Entity $entity): INode
73
    {
74
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
75
        if ($entity->isProtected()) {
76
            $attributes[Html5::ATTR_CHECKED] = null;
77
        }
78
        $input = new Input(
79
            'protected',
80
            'protected',
81
            '1',
82
            [],
83
            $attributes
84
        );
85
        $label = new Label('protected', 'website:contentListProtected');
86
        $help  = new Help('website:contentListProtectedHelp');
87
88
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'protected-container']);
89
    }
90
91
    /**
92
     * @param Entity $entity
93
     *
94
     * @return INode
95
     */
96
    protected function addWithImage(Entity $entity): INode
97
    {
98
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
99
        if ($entity->isWithImage()) {
100
            $attributes[Html5::ATTR_CHECKED] = null;
101
        }
102
        $input = new Input(
103
            'with_image',
104
            'with_image',
105
            '1',
106
            [],
107
            $attributes
108
        );
109
        $label = new Label('with_image', 'website:contentListWithImage');
110
        $help  = new Help('website:contentListWithImageHelp');
111
112
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'withImage-container']);
113
    }
114
115
    /**
116
     * @param Entity $entity
117
     * @param bool   $isAdvancedAllowed
118
     *
119
     * @return INode
120
     */
121
    protected function addWithLinks(Entity $entity): INode
122
    {
123
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
124
        if ($entity->isWithLinks()) {
125
            $attributes[Html5::ATTR_CHECKED] = null;
126
        }
127
        $input = new Input(
128
            'with_links',
129
            'with_links',
130
            '1',
131
            [],
132
            $attributes
133
        );
134
        $label = new Label('with_links', 'website:contentListWithLinks');
135
        $help  = new Help('website:contentListWithLinksHelp');
136
137
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'withLinks-container']);
138
    }
139
140
    /**
141
     * @param Entity $entity
142
     * @param bool   $isAdvancedAllowed
143
     *
144
     * @return INode
145
     */
146
    protected function addWithHtml(Entity $entity): INode
147
    {
148
        $attributes = [Html5::ATTR_TYPE => Input::TYPE_CHECKBOX];
149
        if ($entity->isWithHtml()) {
150
            $attributes[Html5::ATTR_CHECKED] = null;
151
        }
152
        $input = new Input(
153
            'with_html',
154
            'with_html',
155
            '1',
156
            [],
157
            $attributes
158
        );
159
        $label = new Label('with_html', 'website:contentListWithHtml');
160
        $help  = new Help('website:contentListWithHtmlHelp');
161
162
        return new CheckboxGroup($input, $label, $help, [], [Html5::ATTR_ID => 'withHtml-container']);
163
    }
164
}
165