Completed
Push — master ( 6e1c48...7d90f1 )
by John
03:00
created

StrictSimpleObjectFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 34.15 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 14
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B supports() 14 14 5
A getPriority() 0 4 1
A instantiate() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Descriptions\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\Descriptions\Hydrator\Processors\Factory;
10
11
use KleijnWeb\PhpApi\Descriptions\Description\Schema\ObjectSchema;
12
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
13
use KleijnWeb\PhpApi\Descriptions\Hydrator\ProcessorBuilder;
14
use KleijnWeb\PhpApi\Descriptions\Hydrator\Processors\Object\ObjectProcessor;
15
use KleijnWeb\PhpApi\Descriptions\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