Passed
Pull Request — master (#323)
by Fabien
02:12
created

MinScoreToShow::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 16
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Configuration\Validator;
6
7
use Churn\Configuration\Config;
8
use Churn\Configuration\Validator;
9
use Webmozart\Assert\Assert;
10
11
/**
12
 * @internal
13
 */
14
final class MinScoreToShow implements Validator
15
{
16
    private const KEY = 'minScoreToShow';
17
18
    /**
19
     * Returns the configuration key.
20
     */
21
    public function getKey(): string
22
    {
23
        return self::KEY;
24
    }
25
26
    /**
27
     * @param Config $config The configuration object.
28
     * @param array<mixed> $configuration The array containing the configuration values.
29
     */
30
    public function validate(Config $config, array $configuration): void
31
    {
32
        if (!\array_key_exists(self::KEY, $configuration)) {
33
            return;
34
        }
35
36
        $value = $configuration[self::KEY];
37
        if (null === $value) {
38
            $config->setMinScoreToShow(null);
39
40
            return;
41
        }
42
43
        Assert::numeric($value, 'Minimum score to show should be a number');
44
45
        $config->setMinScoreToShow((float) $value);
46
    }
47
}
48