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

ParametersTrait::ensure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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