Passed
Push — master ( 8f795d...5bb79c )
by K
01:50
created

WhitelistValidationStrategy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace PerfectApp\Validation;
4
5
class WhitelistValidationStrategy implements ValidationStrategy
6
{
7
    /**
8
     * @param array $whitelist
9
     */
10 2
    public function __construct(private array $whitelist)
11
    {
12 2
    }
13
14
    /**
15
     * @param $data
16
     * @return bool
17
     */
18 2
    public function validate($data): bool
19
    {
20 2
        foreach ($data as $key => $val) {
21 2
            if (!in_array($key, $this->whitelist, true)) {
22 1
                return false; // Validation failed
23
            }
24
        }
25
26 1
        return true; // Validation passed
27
    }
28
}
29