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

WhitelistValidationStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 5
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A validate() 0 9 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