CarbonPlugin::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
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