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

UniqueValueValidator::match()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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