Completed
Push — master ( 1644a3...6b640a )
by Tomasz
02:29
created

InArray   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B getMessage() 0 15 5
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Hop\Validator\Validator;
6
7
class InArray implements RuleValidator
8
{
9
    use IsValidTrait;
10
11 5
    public function getMessage($value, ?array $options)
12
    {
13 5
        if ($options === null || !isset($options['haystack'])) {
14 2
            throw new \InvalidArgumentException('Haystack parameter must be passed in options');
15
        }
16
17 3
        if (\count($options['haystack']) === 0) {
18 1
            throw new \InvalidArgumentException('Haystack parameter must not be an empty array');
19
        }
20
21 2
        if (!\in_array((string)$value, $options['haystack'], true)) {
22 1
            return sprintf('Option \'%s\' not found in passed haystack', $value);
23
        }
24
25 1
        return null;
26
    }
27
}
28