Completed
Pull Request — master (#615)
by Filippo
14:02 queued 03:29
created

NoObjectExists   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 13 2
1
<?php
2
3
namespace DoctrineModule\Validator;
4
5
/**
6
 * Class that validates if objects does not exist in a given repository with a given list of matched fields
7
 *
8
 * @license MIT
9
 * @link    http://www.doctrine-project.org/
10
 * @since   0.4.0
11
 * @author  Marco Pivetta <[email protected]>
12
 */
13
class NoObjectExists extends ObjectExists
14
{
15
    /**
16
     * Error constants
17
     */
18
    const ERROR_OBJECT_FOUND = 'objectFound';
19
20
    /**
21
     * @var array Message templates
22
     */
23
    protected $messageTemplates = [
24
        self::ERROR_OBJECT_FOUND    => "An object matching '%value%' was found",
25
    ];
26
27
    /**
28
     * {@inheritDoc}
29
     */
30 3
    public function isValid($value)
31
    {
32 3
        $cleanedValue = $this->cleanSearchValue($value);
33 3
        $match        = $this->objectRepository->findOneBy($cleanedValue);
34
35 3
        if (is_object($match)) {
36 2
            $this->error(self::ERROR_OBJECT_FOUND, $value);
37
38 2
            return false;
39
        }
40
41 1
        return true;
42
    }
43
}
44