Completed
Push — master ( c34cac...3c68a7 )
by Pieter
04:47
created

DateTimePlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDynamicSchemaLogic() 0 3 1
A getNormalizers() 0 4 1
A getDefinedStaticData() 0 5 1
1
<?php
2
3
4
namespace W2w\Lib\Apie\Plugins\DateTime;
5
6
use DateTimeInterface;
7
use Doctrine\Common\Annotations\AnnotationReader;
8
use erasys\OpenApi\Spec\v3\Schema;
9
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
10
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
11
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
12
use W2w\Lib\Apie\PluginInterfaces\NormalizerProviderInterface;
13
use W2w\Lib\Apie\PluginInterfaces\SchemaProviderInterface;
14
15
final class DateTimePlugin implements NormalizerProviderInterface, SchemaProviderInterface
16
{
17
    /**
18
     * @return NormalizerInterface[]|DenormalizerInterface[]
19
     */
20
    public function getNormalizers(): array
21
    {
22
        return [
23
            new DateTimeNormalizer([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'])
24
        ];
25
    }
26
27
    /**
28
     * @return Schema[]
29
     */
30
    public function getDefinedStaticData(): array
31
    {
32
        AnnotationReader::addGlobalIgnoredName('alias');
33
        return [
34
            DateTimeInterface::class => new Schema(['type' => 'string', 'format' => 'date-time'])
35
        ];
36
    }
37
38
    /**
39
     * @return callable[]
40
     */
41
    public function getDynamicSchemaLogic(): array
42
    {
43
        return [];
44
    }
45
}
46