Passed
Push — 0.x ( 689b78...ec4bb9 )
by Pavel
02:17
created

ParametersTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 7
c 0
b 0
f 0
dl 0
loc 30
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 3 1
A get() 0 3 1
A all() 0 3 1
A ensure() 0 3 1
A has() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DigitalCz\OpenIDConnect\Discovery\Traits;
6
7
use DigitalCz\OpenIDConnect\Discovery\Exception\MetadataException;
8
9
trait ParametersTrait
10
{
11
    /** @var array<string, mixed> */
12
    private array $parameters = [];
13
14
    public function has(string $key): bool
15
    {
16
        return isset($this->parameters[$key]);
17
    }
18
19
    public function get(string $key, mixed $default = null): mixed
20
    {
21
        return $this->parameters[$key] ?? $default;
22
    }
23
24
    public function ensure(string $key): mixed
25
    {
26
        return $this->get($key) ?? MetadataException::missing($key);
27
    }
28
29
    /** @return array<string, mixed> */
30
    public function all(): array
31
    {
32
        return $this->parameters;
33
    }
34
35
    /** @return array<string, mixed> */
36
    public function jsonSerialize(): array
37
    {
38
        return $this->all();
39
    }
40
}
41