|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Churn\Configuration\Validator; |
|
6
|
|
|
|
|
7
|
|
|
use Churn\Configuration\EditableConfig; |
|
8
|
|
|
use Webmozart\Assert\Assert; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @internal |
|
12
|
|
|
*/ |
|
13
|
|
|
final class CommitsSince extends BaseValidator |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Class constructor. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct() |
|
19
|
|
|
{ |
|
20
|
|
|
parent::__construct('commitsSince'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param EditableConfig $config The configuration object. |
|
25
|
|
|
* @param array<mixed> $configuration The array containing the configuration values. |
|
26
|
|
|
*/ |
|
27
|
|
|
public function validate(EditableConfig $config, array $configuration): void |
|
28
|
|
|
{ |
|
29
|
|
|
if (!$this->hasConfigurationKey($configuration)) { |
|
30
|
|
|
return; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** @var mixed $value */ |
|
34
|
|
|
$value = $configuration[$this->key]; |
|
35
|
|
|
|
|
36
|
|
|
$this->validateValue($config, $value); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param EditableConfig $config The configuration object. |
|
41
|
|
|
* @param mixed $value The value to validate. |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function validateValue(EditableConfig $config, $value): void |
|
44
|
|
|
{ |
|
45
|
|
|
Assert::string($value, 'Commits since should be a string'); |
|
46
|
|
|
|
|
47
|
|
|
$config->setCommitsSince($value); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param array<mixed> $configuration The array containing the configuration values. |
|
52
|
|
|
*/ |
|
53
|
|
|
private function hasConfigurationKey(array $configuration): bool |
|
54
|
|
|
{ |
|
55
|
|
|
if (\array_key_exists($this->key, $configuration)) { |
|
56
|
|
|
return true; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (\array_key_exists('commitSince', $configuration)) { |
|
60
|
|
|
$this->key = 'commitSince'; |
|
61
|
|
|
\trigger_error( |
|
62
|
|
|
'The "commitSince" configuration key is deprecated and won\'t be supported' |
|
63
|
|
|
. ' in the next major version anymore. Use "commitsSince" instead.', |
|
64
|
|
|
\E_USER_DEPRECATED |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|