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

FilesToShow   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 3 1
A validate() 0 11 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 FilesToShow implements Validator
15
{
16
    private const KEY = 'filesToShow';
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
38
        Assert::integer($value, 'Files to show should be an integer');
39
40
        $config->setFilesToShow($value);
41
    }
42
}
43