InArray::getMessage()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

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