JsonSchemaLinkHeaderModule   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
A __construct() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\Module;
6
7
use BEAR\Resource\Exception\InvalidSchemaUriException;
8
use Override;
9
use Ray\Di\AbstractModule;
10
11
use function filter_var;
12
13
use const FILTER_VALIDATE_URL;
14
15
final class JsonSchemaLinkHeaderModule extends AbstractModule
16
{
17
    /** @param string $jsonSchemaHost Json-schema host name ex) https://example.com/schema/ */
18
    public function __construct(
19
        private readonly string $jsonSchemaHost,
20
        AbstractModule|null $module = null,
21
    ) {
22
        if (! filter_var($jsonSchemaHost, FILTER_VALIDATE_URL)) {
23
            throw new InvalidSchemaUriException($jsonSchemaHost);
24
        }
25
26
        parent::__construct($module);
27
    }
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    #[Override]
33
    protected function configure(): void
34
    {
35
        $this->bind()->annotatedWith('json_schema_host')->toInstance($this->jsonSchemaHost);
36
    }
37
}
38