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
|
|
|
#[\Override] |
28
|
|
|
public function validate(EditableConfig $config, array $configuration): void |
29
|
|
|
{ |
30
|
|
|
if (!$this->hasConfigurationKey($configuration)) { |
31
|
|
|
return; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** @var mixed $value */ |
35
|
|
|
$value = $configuration[$this->key]; |
36
|
|
|
|
37
|
|
|
$this->validateValue($config, $value); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param EditableConfig $config The configuration object. |
42
|
|
|
* @param mixed $value The value to validate. |
43
|
|
|
*/ |
44
|
|
|
#[\Override] |
45
|
|
|
protected function validateValue(EditableConfig $config, $value): void |
46
|
|
|
{ |
47
|
|
|
Assert::string($value, 'Commits since should be a string'); |
48
|
|
|
|
49
|
|
|
$config->setCommitsSince($value); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array<mixed> $configuration The array containing the configuration values. |
54
|
|
|
*/ |
55
|
|
|
private function hasConfigurationKey(array $configuration): bool |
56
|
|
|
{ |
57
|
|
|
if (\array_key_exists($this->key, $configuration)) { |
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (\array_key_exists('commitSince', $configuration)) { |
62
|
|
|
$this->key = 'commitSince'; |
63
|
|
|
\trigger_error( |
64
|
|
|
'The "commitSince" configuration key is deprecated and won\'t be supported' |
65
|
|
|
. ' in the next major version anymore. Use "commitsSince" instead.', |
66
|
|
|
\E_USER_DEPRECATED |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
return true; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return false; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|