AbstractFormData   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
dl 0
loc 45
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSelectOptions() 0 3 1
A setSelectOptions() 0 3 1
A getValue() 0 3 1
A setValue() 0 3 1
1
<?php
2
namespace SKien\Formgenerator;
3
4
/**
5
 * Abstract class representing data for the FormGenerator.
6
 *
7
 * @package Formgenerator
8
 * @author Stefanius <[email protected]>
9
 * @copyright MIT License - see the LICENSE file for details
10
 */
11
abstract class AbstractFormData implements FormDataInterface
12
{
13
    /** @var array<string,mixed> containing all data that can be edited by the form     */
14
    protected array $aValues;
15
    /** @var array<string,array<int|string,string>> containing select list to be displayed by the form     */
16
    protected array $aSelectOptions;
17
18
    /**
19
     * Get the value for the specified element.
20
     * @param string $strName   name of the element
21
     * @return mixed empty string, if no value for requested element available
22
     */
23
    public function getValue(string $strName)
24
    {
25
        return $this->aValues[$strName] ?? '';
26
    }
27
28
    /**
29
     * Get the select options for specified element.
30
     * @param string $strName   name of the element
31
     * @return array<int|string,string> empty array, if no options for requested element available
32
     */
33
    public function getSelectOptions(string $strName) : array
34
    {
35
        return $this->aSelectOptions[$strName] ?? [];
36
    }
37
38
    /**
39
     * Set value for specified element.
40
     * @param string $strName   name of the element
41
     * @param mixed $value      value to set
42
     */
43
    public function setValue(string $strName, $value) : void
44
    {
45
        $this->aValues[$strName] = $value;
46
    }
47
48
    /**
49
     * Set select options for specified element.
50
     * @param string $strName  name of the element
51
     * @param array<int|string,string> $aOptions  associative array with 'option' => value elements
52
     */
53
    public function setSelectOptions(string $strName, array $aOptions) : void
54
    {
55
        $this->aSelectOptions[$strName] = $aOptions;
56
    }
57
}
58
59