Completed
Push — master ( 638b8d...de83b5 )
by John
01:47 queued 17s
created

StrictSimpleObjectFactory::supports()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 3
nop 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\ObjectSchema;
12
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
13
use KleijnWeb\PhpApi\Hydrator\ProcessorBuilder;
14
use KleijnWeb\PhpApi\Hydrator\Processors\Object\ObjectProcessor;
15
use KleijnWeb\PhpApi\Hydrator\Processors\Object\StrictSimpleObjectProcessor;
16
17
/**
18
 * @author John Kleijn <[email protected]>
19
 */
20
class StrictSimpleObjectFactory extends ObjectFactory
21
{
22
    const PRIORITY = 600;
23
24
    /**
25
     * @param Schema $schema
26
     * @return bool
27
     */
28 View Code Duplication
    public function supports(Schema $schema): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        /** @var ObjectSchema $schema */
31
        if (!parent::supports($schema) || $schema->hasComplexType()) {
32
            return false;
33
        }
34
35
        if (!isset($schema->getDefinition()->additionalProperties)
36
            || $schema->getDefinition()->additionalProperties) {
37
            return false;
38
        }
39
40
        return true;
41
    }
42
43
    /**
44
     * @return int
45
     */
46
    public function getPriority(): int
47
    {
48
        return self::PRIORITY;
49
    }
50
51
    /**
52
     * @param ObjectSchema     $schema
53
     * @param ProcessorBuilder $builder
54
     * @return ObjectProcessor
55
     */
56
    protected function instantiate(ObjectSchema $schema, ProcessorBuilder $builder): ObjectProcessor
57
    {
58
        return new StrictSimpleObjectProcessor($schema);
59
    }
60
}
61