Completed
Push — master ( 296743...12eab9 )
by Kirill
36:17
created

UniqueValueValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 27
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 4 2
A validate() 0 7 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Reflection\Validation\Uniqueness\Scalar;
11
12
use Railt\SDL\Exceptions\TypeConflictException;
13
use Railt\SDL\Reflection\Validation\Base\BaseValidator;
14
use Railt\SDL\Reflection\Validation\Uniqueness\ScalarUniquenessValidator;
15
16
/**
17
 * Class UniqueValueValidator
18
 */
19
class UniqueValueValidator extends BaseValidator implements ScalarUniquenessValidator
20
{
21
    /**
22
     * @param array $container
23
     * @param string $item
24
     * @return bool
25
     */
26 6576
    public function match($container, $item): bool
27
    {
28 6576
        return \is_array($container) && \is_string($item);
29
    }
30
31
    /**
32
     * @param array $container
33
     * @param string $item
34
     * @param string $typeName
35
     * @return void
36
     * @throws TypeConflictException
37
     */
38 2436
    public function validate(array $container, string $item, string $typeName): void
39
    {
40 2436
        if (\array_key_exists($item, $container)) {
41
            $error = \sprintf(static::REDEFINITION_ERROR, $typeName . ' ' . $item);
42
            throw new TypeConflictException($error, $this->getCallStack());
43
        }
44 2436
    }
45
}
46