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

AnyFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 40
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A create() 8 8 2
A getPriority() 4 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\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\Schema;
13
use KleijnWeb\PhpApi\Hydrator\DateTimeSerializer;
14
use KleijnWeb\PhpApi\Hydrator\ProcessorBuilder;
15
use KleijnWeb\PhpApi\Hydrator\Processors\AnyProcessor;
16
use KleijnWeb\PhpApi\Hydrator\Processors\Processor;
17
18
/**
19
 * @author John Kleijn <[email protected]>
20
 */
21 View Code Duplication
class AnyFactory implements Factory
0 ignored issues
show
Duplication introduced by
This class 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...
22
{
23
    const PRIORITY = 1000;
24
25
    /**
26
     * @var DateTimeSerializer
27
     */
28
    protected $dateTimeSerializer;
29
30
    /**
31
     * DateTimeFactory constructor.
32
     * @param DateTimeSerializer $dateTimeSerializer
33
     */
34
    public function __construct(DateTimeSerializer $dateTimeSerializer)
35
    {
36
        $this->dateTimeSerializer = $dateTimeSerializer;
37
    }
38
39
    /**
40
     * @param Schema           $schema
41
     * @param ProcessorBuilder $builder
42
     * @return Processor|null
43
     */
44
    public function create(Schema $schema, ProcessorBuilder $builder)
45
    {
46
        if (!$schema instanceof AnySchema) {
47
            return null;
48
        }
49
50
        return new AnyProcessor(new AnySchema(), $this->dateTimeSerializer);
51
    }
52
53
    /**
54
     * @return int
55
     */
56
    public function getPriority(): int
57
    {
58
        return self::PRIORITY;
59
    }
60
}
61