Entry   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 61
rs 10
ccs 15
cts 15
cp 1
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSource() 0 3 1
A __toString() 0 3 1
A availableSource() 0 3 2
A setEntry() 0 6 1
A getKey() 0 3 1
A getValue() 0 3 1
1
<?php
2
3
namespace kalanis\kw_input\Entries;
4
5
6
use kalanis\kw_input\Interfaces;
7
8
9
/**
10
 * Class Entry
11
 * @package kalanis\kw_input\Entries
12
 * Simple entry from source
13
 * For setting numeric value just re-type set by strval()
14
 * For setting boolean value just expand previous - strval(intval())
15
 */
16
class Entry implements Interfaces\IEntry
17
{
18
    protected string $key = '';
19
    /** @var mixed|null */
20
    protected $value = '';
21
    protected string $source = '';
22
23
    /** @var string[] */
24
    protected static array $availableSources = [
25
        self::SOURCE_CLI,
26
        self::SOURCE_GET,
27
        self::SOURCE_POST,
28
        // self::SOURCE_FILES, // has own class
29
        self::SOURCE_COOKIE,
30
        self::SOURCE_SESSION,
31
        self::SOURCE_SERVER,
32
        self::SOURCE_ENV,
33
        self::SOURCE_EXTERNAL,
34
        self::SOURCE_JSON,
35
    ];
36
37
    /**
38
     * @param string $source
39
     * @param string $key
40
     * @param mixed|null $value
41
     * @return Entry
42
     */
43 33
    public function setEntry(string $source, string $key, $value = null): self
44
    {
45 33
        $this->key = $key;
46 33
        $this->value = $value;
47 33
        $this->source = $this->availableSource($source);
48 33
        return $this;
49
    }
50
51 33
    protected function availableSource(string $source): string
52
    {
53 33
        return in_array($source, static::$availableSources) ? $source : $this->source;
54
    }
55
56 23
    public function getSource(): string
57
    {
58 23
        return $this->source;
59
    }
60
61 27
    public function getKey(): string
62
    {
63 27
        return $this->key;
64
    }
65
66
    /**
67
     * @return mixed|null
68
     */
69 24
    public function getValue()
70
    {
71 24
        return $this->value;
72
    }
73
74 5
    public function __toString()
75
    {
76 5
        return strval($this->getValue());
77
    }
78
}
79