Completed
Pull Request — master (#5)
by John
01:37
created

ArrayFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
A getPriority() 0 4 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Hydrator package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\PhpApi\Hydrator\Processors\Factory;
10
11
use KleijnWeb\PhpApi\Descriptions\Description\Schema\ArraySchema;
12
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
13
use KleijnWeb\PhpApi\Hydrator\ProcessorBuilder;
14
use KleijnWeb\PhpApi\Hydrator\Processors\ArrayProcessor;
15
use KleijnWeb\PhpApi\Hydrator\Processors\Processor;
16
17
/**
18
 * @author John Kleijn <[email protected]>
19
 */
20
class ArrayFactory implements Factory
21
{
22
    const PRIORITY = 800;
23
24
    /**
25
     * @param Schema           $schema
26
     * @param ProcessorBuilder $builder
27
     * @return Processor|null
28
     */
29
    public function create(Schema $schema, ProcessorBuilder $builder)
30
    {
31
        if (!$schema instanceof ArraySchema) {
32
            return null;
33
        }
34
35
        return (new ArrayProcessor($schema))
36
            ->setItemsProcessor($builder->build($schema->getItemsSchema()));
37
    }
38
39
    /**
40
     * @return int
41
     */
42
    public function getPriority(): int
43
    {
44
        return self::PRIORITY;
45
    }
46
}
47