EntityNotExists   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 35
loc 35
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 13 13 2

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
 * 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