UniqueUsername   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 24
ccs 5
cts 5
cp 1
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getTargets() 0 9 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Validator/Constraints/UniqueUsername.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Validator\Constraints;
10
11
use Attribute;
12
use Symfony\Component\Validator\Constraint;
13
14
/**
15
 * Class UniqueUsername
16
 *
17
 * Usage example;
18
 *  App\Validator\Constraints\UniqueUsername()
19
 *
20
 * Just add that to your class as an annotation and you're good to go.
21
 *
22
 * @Annotation
23
 * @Target({"CLASS"})
24
 *
25
 * @package App\Validator\Constraints
26
 * @author TLe, Tarmo Leppänen <[email protected]>
27
 */
28
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
29
class UniqueUsername extends Constraint
30
{
31
    final public const IS_UNIQUE_USERNAME_ERROR = 'ea62740a-4d9b-4a25-9a56-46fb4c3d5fea';
32
    final public const MESSAGE = 'This username is already taken.';
33
34
    /**
35
     * {@inheritdoc}
36
     *
37
     * @psalm-var array<string, string>
38
     */
39
    protected const ERROR_NAMES = [
40
        self::IS_UNIQUE_USERNAME_ERROR => 'IS_UNIQUE_USERNAME_ERROR',
41
    ];
42
43 39
    public function getTargets(): string
44
    {
45 39
        $output = null;
46
47 39
        if (parent::getTargets() !== self::CLASS_CONSTRAINT) {
48 39
            $output = self::CLASS_CONSTRAINT;
49
        }
50
51 39
        return $output ?? self::CLASS_CONSTRAINT;
52
    }
53
}
54