CompoundIndex   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 14.63 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 6
loc 41
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
ccs 0
cts 20
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 6 18 4
A getDefinition() 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
2
/**
3
 * File was created 01.03.2016 12:07
4
 */
5
6
namespace PeekAndPoke\Component\Slumber\Annotation\Slumber\Store;
7
8
use Doctrine\Common\Annotations\Annotation;
9
use PeekAndPoke\Component\Slumber\Annotation\ClassMarker;
10
use PeekAndPoke\Component\Slumber\Annotation\CompoundIndexDefinition;
11
use PeekAndPoke\Component\Slumber\Core\Exception\SlumberException;
12
use PeekAndPoke\Component\Slumber\Core\Validation\ValidationContext;
13
14
/**
15
 * @Annotation
16
 * @Annotation\Target("CLASS")
17
 *
18
 * @author Karsten J. Gerber <[email protected]>
19
 */
20
class CompoundIndex extends AbstractIndexDefinition implements ClassMarker, CompoundIndexDefinition
21
{
22
    /**
23
     * @var array
24
     *
25
     * @Annotation\Required()
26
     */
27
    public $def = [];
28
29
    /**
30
     * @param ValidationContext $context
31
     *
32
     * @throws SlumberException
33
     */
34
    public function validate(ValidationContext $context)
35
    {
36
        $direction = $this->getDirection();
37
38 View Code Duplication
        if ($direction !== self::ASCENDING && $direction !== self::DESCENDING) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
39
            throw $this->createValidationException(
40
                $context,
41
                'The index direction must be "ASC" or "DESC" but "' . $direction . '" was found.'
42
            );
43
        }
44
45
        if (! \is_array($this->def)) {
46
            throw $this->createValidationException(
47
                $context,
48
                'The compound index definition must be defined as a key value pair. Example: { \'one\': 1, \'two\': -1 }'
49
            );
50
        }
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getDefinition()
57
    {
58
        return $this->def;
59
    }
60
}
61