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

LooseSimpleObjectFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 31.82 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 14
loc 44
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 7 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\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\AnySchema;
12
use KleijnWeb\PhpApi\Descriptions\Description\Schema\ObjectSchema;
13
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
14
use KleijnWeb\PhpApi\Hydrator\ProcessorBuilder;
15
use KleijnWeb\PhpApi\Hydrator\Processors\AnyProcessor;
16
use KleijnWeb\PhpApi\Hydrator\Processors\Object\LooseSimpleObjectProcessor;
17
use KleijnWeb\PhpApi\Hydrator\Processors\Object\ObjectProcessor;
18
19
/**
20
 * @author John Kleijn <[email protected]>
21
 */
22
class LooseSimpleObjectFactory extends ObjectFactory
23
{
24
    const PRIORITY = 500;
25
26
    /**
27
     * @param Schema $schema
28
     * @return bool
29
     */
30 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...
31
    {
32
        /** @var ObjectSchema $schema */
33
        if (!parent::supports($schema) || $schema->hasComplexType()) {
34
            return false;
35
        }
36
37
        if (isset($schema->getDefinition()->additionalProperties)
38
            && !$schema->getDefinition()->additionalProperties) {
39
            return false;
40
        }
41
42
        return true;
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    public function getPriority(): int
49
    {
50
        return self::PRIORITY;
51
    }
52
53
    /**
54
     * @param ObjectSchema     $schema
55
     * @param ProcessorBuilder $builder
56
     * @return ObjectProcessor
57
     */
58
    public function instantiate(ObjectSchema $schema, ProcessorBuilder $builder): ObjectProcessor
59
    {
60
        /** @var AnyProcessor $anyProcessor */
61
        $anyProcessor = $builder->build(new AnySchema());
62
63
        return new LooseSimpleObjectProcessor($schema, $anyProcessor);
64
    }
65
}
66