MultipleValue   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 17
c 1
b 0
f 0
dl 0
loc 51
rs 10
ccs 26
cts 26
cp 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A setDataSourceConnector() 0 3 1
A __construct() 0 5 1
A getAlias() 0 6 3
A getField() 0 3 1
A renderContent() 0 5 1
A setForm() 0 3 1
1
<?php
2
3
namespace kalanis\kw_table\form_kw\Fields;
4
5
6
use kalanis\kw_connect\core\Interfaces\IIterableConnector;
7
use kalanis\kw_forms\Exceptions\RenderException;
8
use kalanis\kw_forms\Form;
9
use kalanis\kw_table\core\Connector\AMultipleValue;
10
use kalanis\kw_table\core\TableException;
11
12
13
/**
14
 * Class MultipleValue
15
 * @package kalanis\kw_table\form_kw\Fields
16
 */
17
class MultipleValue extends AMultipleValue
18
{
19
    protected AField $field;
20
21 2
    public function __construct(AField $field, ?string $label = null, string $alias = '')
22
    {
23 2
        $this->field = $field;
24 2
        $this->alias = $alias;
25 2
        $this->label = $label;
26 2
    }
27
28 2
    public function getAlias(): string
29
    {
30 2
        return empty($this->alias)
31 1
            ? (empty($this->columnName)
32 1
                ? $this->field->getAlias() : $this->columnName)
33 2
            : $this->alias
34
        ;
35
    }
36
37 2
    public function getField(): AField
38
    {
39 2
        return $this->field;
40
    }
41
42 2
    public function setDataSourceConnector(IIterableConnector $dataSource): void
43
    {
44 2
        $this->field->setDataSourceConnector($dataSource);
45 2
    }
46
47 2
    public function setForm(Form $form): void
48
    {
49 2
        $this->field->setForm($form);
50 2
    }
51
52 2
    public function add(): void
53
    {
54 2
        $this->field->setAlias($this->getAlias());
55 2
        $this->field->add();
56 2
    }
57
58
    /**
59
     * @throws RenderException
60
     * @throws TableException
61
     * @return string
62
     */
63 2
    public function renderContent(): string
64
    {
65 2
        $control = $this->field->getFormInstance()->getControl($this->getAlias());
66 2
        $control->setLabel($this->getLabel());
67 2
        return $control->render();
68
    }
69
}
70