Skip to content

Commit 45aac08

Browse files
committed
Resolve rule params with default value
1 parent 22b22c0 commit 45aac08

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Application/Rule/Rules/HasChangesRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use ArtARTs36\MergeRequestLinter\Domain\Rule\Rule;
1818
use ArtARTs36\MergeRequestLinter\Domain\Rule\RuleDefinition;
1919

20-
#[Description('Merge Request must have changes in {files}.')]
20+
#[Description('Merge Request must have {changes}.')]
2121
class HasChangesRule implements Rule
2222
{
2323
public const NAME = '@mr-linter/has_changes';

src/Shared/Reflection/ParameterMapBuilder.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ public function build(Instantiator $constructor, array $params): array
2424
$args = [];
2525

2626
foreach ($constructor->params() as $paramName => $param) {
27-
$args[$paramName] = $this->argResolver->resolve($param->type, $params[$paramName] ?? null);
27+
$val = null;
28+
29+
if (! array_key_exists($paramName, $params) && $param->hasDefaultValue) {
30+
$val = $param->getDefaultValue();
31+
} else {
32+
$val = $this->argResolver->resolve($param->type, $params[$paramName] ?? null);
33+
}
34+
35+
$args[$paramName] = $val;
2836
}
2937

3038
return $args;

tests/Unit/Application/Rule/Rules/TitleStartsWithTaskNumberRuleTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public function providerForTestLint(): array
4747
'projectCodes' => ['TASK'],
4848
'expectedNotes' => ['Title must starts with task number of projects [TASK]'],
4949
],
50+
[
51+
$this->makeMergeRequest([
52+
'title' => 'TASK-1 project',
53+
]),
54+
'projectCodes' => ['TASKA'],
55+
'expectedNotes' => ['Title starts with task number of unknown project "TASK"'],
56+
],
5057
];
5158
}
5259

0 commit comments

Comments
 (0)