CompoundIndex::validate()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18

Duplication

Lines 6
Ratio 33.33 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 6
loc 18
ccs 0
cts 16
cp 0
rs 9.6666
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 20
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