VarsAdapter::getSource()   A
last analyzed

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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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