DomainPlugin::getDynamicSchemaLogic()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace W2w\Lib\ApieDomainPlugin;
5
6
use erasys\OpenApi\Spec\v3\Schema;
7
use Pdp\Cache;
8
use Pdp\CurlHttpClient;
9
use Pdp\Domain;
10
use Pdp\Manager;
11
use Pdp\PublicSuffix;
12
use Pdp\Rules;
13
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
14
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
15
use W2w\Lib\Apie\PluginInterfaces\NormalizerProviderInterface;
16
use W2w\Lib\Apie\PluginInterfaces\SchemaProviderInterface;
17
use W2w\Lib\ApieDomainPlugin\Normalizers\DomainNormalizer;
18
use W2w\Lib\ApieDomainPlugin\Normalizers\PublicSuffixNormalizer;
19
20
/**
21
 * Apie plugin to add support for Pdp\Domain.
22
 */
23
class DomainPlugin implements SchemaProviderInterface, NormalizerProviderInterface
24
{
25
    private $rules;
26
27
    /**
28
     * @param Rules|null $rules
29
     */
30
    public function __construct(?Rules $rules = null)
31
    {
32
        if (!$rules) {
33
            $manager = new Manager(new Cache(), new CurlHttpClient());
34
            $rules = $manager->getRules();
35
        }
36
        $this->rules = $rules;
37
    }
38
39
    /**
40
     * @return Schema[]
41
     */
42
    public function getDefinedStaticData(): array
43
    {
44
        return [
45
            Domain::class => new Schema(['type' => 'string', 'format' => 'domain', 'example' => 'example.nl', 'default' => 'example.nl']),
46
            PublicSuffix::class => new Schema(['type' => 'string', 'format' => 'tld', 'example' => 'nl', 'default' => 'nl']),
47
        ];
48
    }
49
50
    /**
51
     * @return callable[]
52
     */
53
    public function getDynamicSchemaLogic(): array
54
    {
55
        return [];
56
    }
57
58
    /**
59
     * @return NormalizerInterface[]|DenormalizerInterface[]
60
     */
61
    public function getNormalizers(): array
62
    {
63
        return [new DomainNormalizer($this->rules), new PublicSuffixNormalizer($this->rules)];
64
    }
65
}
66