Passed
Pull Request — 5.x (#26)
by Enjoys
04:01 queued 01:55
created

Group::prepare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Forms\Elements;
6
7
use Enjoys\Forms\Element;
8
use Enjoys\Forms\Interfaces\Descriptionable;
9
use Enjoys\Forms\Renderer\Html\HtmlRenderer;
10
use Enjoys\Forms\Traits\Container;
11
use Enjoys\Forms\Traits\Description;
12
use Webmozart\Assert\Assert;
13
14
class Group extends Element implements Descriptionable
15
{
16
    use Description;
17
    use Container;
18
19 11
    public function __construct(string $title = null, string $id = null)
20
    {
21 11
        parent::__construct($id ?? \uniqid('group'), $title);
22
    }
23
24
    /**
25
     * @param Element[] $elements
26
     * @return $this
27
     */
28 6
    public function add(array $elements = []): Group
29
    {
30 6
        foreach ($elements as $element) {
31
            /** @psalm-suppress RedundantConditionGivenDocblockType */
32 6
            Assert::isInstanceOf($element, Element::class);
33 5
            $element->setForm($this->getForm());
34 5
            $this->addElement($element);
35
        }
36 5
        return $this;
37
    }
38
39 3
    public function baseHtml(): string
40
    {
41 3
        $return = sprintf("<div id='%s'>", $this->getName());
42 3
        foreach ($this->getElements() as $data) {
43
//            $data->setAttribute(AttributeFactory::create('placeholder', $data->getLabel()));
44
//            $data->setLabel(null);
45 3
            $return .= HtmlRenderer::createTypeRender($data)->render();
46
        }
47 3
        $return .= '</div>';
48 3
        return $return;
49
    }
50
51 5
    public function prepare(): bool
52
    {
53 5
        return false;
54
    }
55
}
56