JsonSchemaLinkHeaderModule::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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