VarsAdapter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 34
ccs 16
cts 16
cp 1
rs 10
c 2
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSource() 0 3 1
A loadEntries() 0 10 3
A loadVars() 0 9 3
1
<?php
2
3
namespace kalanis\kw_forms\Adapters;
4
5
6
use kalanis\kw_forms\Exceptions\FormsException;
7
use kalanis\kw_input\Interfaces\IEntry;
8
9
10
class VarsAdapter extends AAdapter
11
{
12
    protected string $inputType = '';
13
14 3
    public function loadEntries(string $inputType): void
15
    {
16 3
        if (IEntry::SOURCE_POST == $inputType) {
17 1
            $this->vars = $this->loadVars($_POST);
18 2
        } elseif (IEntry::SOURCE_GET == $inputType) {
19 1
            $this->vars = $this->loadVars($_GET);
20
        } else {
21 1
            throw new FormsException(sprintf('Unknown input type - %s', $inputType));
22
        }
23 2
        $this->inputType = $inputType;
24 2
    }
25
26
    /**
27
     * @param array<string|int, string|int|float|bool|null>|null $array
28
     * @return array<string, string>
29
     */
30 3
    protected function loadVars(&$array): array
31
    {
32 3
        $result = [];
33 3
        if (is_array($array)) {
34 2
            foreach ($array as $postedKey => $posted) {
35 1
                $result[$this->removeNullBytes(strval($postedKey))] = $this->removeNullBytes(strval($posted));
36
            }
37
        }
38 3
        return $result;
39
    }
40
41 4
    public function getSource(): string
42
    {
43 4
        return $this->inputType;
44
    }
45
}
46