| Total Complexity | 7 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 |
|
| 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() |
|
| 77 | } |
||
| 78 | } |
||
| 79 |