Passed
Push — feature/initial-implementation ( 3b7c72...40c5a6 )
by Fike
01:49
created

AbstractParameter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
wmc 4
dl 27
loc 27
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A nullValueAllowed() 3 3 1
A getInstance() 7 7 2
A getFriendlyId() 3 3 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
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Mapping\Type\Parameter\Infrastructure;
6
7
use AmaTeam\ElasticSearch\API\Mapping\Type\ParameterInterface;
8
9 View Code Duplication
abstract class AbstractParameter implements ParameterInterface
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...
10
{
11
    /**
12
     * @var AbstractParameter[]
13
     */
14
    protected static $registry = [];
15
16
    public function getFriendlyId(): string
17
    {
18
        return $this->getId();
19
    }
20
21
    /**
22
     * @inheritDoc
23
     */
24
    public function nullValueAllowed(): bool
25
    {
26
        return false;
27
    }
28
29
    public static function getInstance()
30
    {
31
        $className = get_called_class();
32
        if (!isset(static::$registry[$className])) {
33
            static::$registry[$className] = new static();
34
        }
35
        return static::$registry[$className];
36
    }
37
}
38