Skip to content

Commit

Permalink
Resolve rule params with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtARTs36 committed Sep 3, 2023
1 parent 22b22c0 commit 45aac08
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Application/Rule/Rules/HasChangesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use ArtARTs36\MergeRequestLinter\Domain\Rule\Rule;
use ArtARTs36\MergeRequestLinter\Domain\Rule\RuleDefinition;

#[Description('Merge Request must have changes in {files}.')]
#[Description('Merge Request must have {changes}.')]
class HasChangesRule implements Rule
{
public const NAME = '@mr-linter/has_changes';
Expand Down
10 changes: 9 additions & 1 deletion src/Shared/Reflection/ParameterMapBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ public function build(Instantiator $constructor, array $params): array
$args = [];

foreach ($constructor->params() as $paramName => $param) {
$args[$paramName] = $this->argResolver->resolve($param->type, $params[$paramName] ?? null);
$val = null;

if (! array_key_exists($paramName, $params) && $param->hasDefaultValue) {
$val = $param->getDefaultValue();
} else {
$val = $this->argResolver->resolve($param->type, $params[$paramName] ?? null);
}

$args[$paramName] = $val;
}

return $args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public function providerForTestLint(): array
'projectCodes' => ['TASK'],
'expectedNotes' => ['Title must starts with task number of projects [TASK]'],
],
[
$this->makeMergeRequest([
'title' => 'TASK-1 project',
]),
'projectCodes' => ['TASKA'],
'expectedNotes' => ['Title starts with task number of unknown project "TASK"'],
],
];
}

Expand Down

0 comments on commit 45aac08

Please sign in to comment.