EntityExistsValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 12 3
1
<?php
2
/**
3
 * @author Stefano Torresi (http://stefanotorresi.it)
4
 * @license See the file LICENSE.txt for copying permission.
5
 * ************************************************
6
 */
7
8
namespace Thorr\Persistence\Validator;
9
10
class EntityExistsValidator extends AbstractEntityValidator
11
{
12
    const ERROR_ENTITY_NOT_EXISTS = 'entityNotExists';
13
14
    /**
15
     * @var array Message templates
16
     */
17
    protected $messageTemplates = [
18
        self::ERROR_ENTITY_NOT_EXISTS => 'Entity not found',
19
    ];
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 2
    public function isValid($value)
25
    {
26 2
        $result = $this->findEntity($value);
27
28 2
        if ($result && ! in_array($result, $this->excluded)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $result of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
29 1
            return true;
30
        }
31
32 1
        $this->error(static::ERROR_ENTITY_NOT_EXISTS);
33
34 1
        return false;
35
    }
36
}
37