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

NoObjectExists::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 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