NoObjectExists   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

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