Skip to content

Commit

Permalink
Restore rule name without builder method
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosas committed Aug 15, 2023
1 parent dbb6e92 commit 7013051
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Test/TestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,28 @@ private function parse(): array
$object = $reflected->newInstanceWithoutConstructor();
foreach ($methods as $method) {
$ruleBuilder = $object->{$method}();
$rules[] = $ruleBuilder;
$rules[$method] = $ruleBuilder;
}
}

return $this->buildRules($rules);
}

/**
* @param array<RuleBuilder> $ruleBuilders
* @param array<string, RuleBuilder> $ruleBuilders
* @return array<Rule>
*/
private function buildRules(array $ruleBuilders): array
{
$rules = array_map(
static fn (RuleBuilder $rule): Rule => $rule(),
$ruleBuilders
static function (string $ruleName, RuleBuilder $builder): Rule {
$rule = $builder();
$rule->ruleName = $ruleName;

return $rule;
},
array_keys($ruleBuilders),
array_values($ruleBuilders)
);

array_walk(
Expand Down

0 comments on commit 7013051

Please sign in to comment.