EntityNotExists::isValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Polder Knowledge / entityservice-zend-validator (https://polderknowledge.com)
4
 *
5
 * @link https://github.com/polderknowledge/entityservice-zend-validator for the canonical source repository
6
 * @copyright Copyright (c) 2016 Polder Knowledge (https://polderknowledge.com)
7
 * @license https://github.com/polderknowledge/entityservice-zend-validator/blob/master/LICENSE.md MIT
8
 */
9
10
namespace PolderKnowledge\EntityService\Validator;
11
12
/**
13
 * The EntityNotExists validator will validate a certain entity was found.
14
 * Validation will fail when the entity is present
15
 */
16 View Code Duplication
class EntityNotExists extends AbstractEntityValidator
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...
17
{
18
    /**
19
     * Error constants
20
     */
21
    const ERROR_OBJECT_FOUND = 'objectFound';
22
23
    /**
24
     * @var array Message templates
25
     */
26
    protected $messageTemplates = array(
27
        self::ERROR_OBJECT_FOUND => "Object matching '%value%' was found",
28
    );
29
30
    /**
31
     * Returns true when $this->entityService returns an empty result
32
     * when $this->method is called with the given criteria
33
     *
34
     * @param mixed $value
35
     * @return boolean
36
     */
37 9
    public function isValid($value)
38
    {
39 9
        $result = $this->fetchResult($value);
40
41
        // A filled array or an object both pass this test causing the error to be set. An empty array or a null value
42
        // will cause the if check to return false. Meaning no error will be set.
43 9
        if ($result) {
44 3
            $this->error(self::ERROR_OBJECT_FOUND, $value);
45 3
            return false;
46
        }
47
48 6
        return true;
49
    }
50
}
51