CarbonPlugin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDynamicSchemaLogic() 0 3 1
A getNormalizers() 0 6 1
A getDefinedStaticData() 0 5 1
1
<?php
2
namespace Apie\CarbonPlugin;
3
4
use Apie\CarbonPlugin\Normalizers\CarbonNormalizer;
5
use Apie\Core\PluginInterfaces\NormalizerProviderInterface;
6
use Apie\Core\PluginInterfaces\SchemaProviderInterface;
7
use Apie\OpenapiSchema\Contract\SchemaContract;
8
use Apie\OpenapiSchema\Factories\SchemaFactory;
9
use DateTimeInterface;
10
use Doctrine\Common\Annotations\AnnotationReader;
11
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
12
13
/**
14
 * Plugin that adds support for Carbon. See https://carbon.nesbot.com/
15
 */
16
final class CarbonPlugin implements NormalizerProviderInterface, SchemaProviderInterface
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21
    public function getNormalizers(): array
22
    {
23
        return [
24
                new CarbonNormalizer(
25
                [
26
                    DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s'
27
                ]
28
            )
29
        ];
30
    }
31
32
    /**
33
     * @return SchemaContract[]
34
     */
35
    public function getDefinedStaticData(): array
36
    {
37
        AnnotationReader::addGlobalIgnoredName('alias');
38
        return [
39
            DateTimeInterface::class => SchemaFactory::createStringSchema('date-time'),
40
        ];
41
    }
42
43
    /**
44
     * @return callable[]
45
     */
46
    public function getDynamicSchemaLogic(): array
47
    {
48
        return [];
49
    }
50
}
51