WhitelistValidationStrategy::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

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