Skip to content

Commit

Permalink
Refactor passing of issue config
Browse files Browse the repository at this point in the history
To avoid falls with variables naming when added new issue property.
  • Loading branch information
Aeliot-Tm committed Jun 17, 2024
1 parent 2c96a13 commit 2371182
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Service/Registrar/JIRA/IssueConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public function __construct(array $config)
'priority' => null,
'tagPrefix' => '',
];
$issue = $config['issue'] + $issueDefaults;
$issue = $config + $issueDefaults;
$this->addTagToLabels = (bool) $issue['addTagToLabels'];
$this->assignee = $issue['assignee'];
$this->components = (array) $issue['components'];
$this->issueType = $issue['type'];
$this->labels = (array) $issue['labels'];
$this->priority = $issue['priority'];
$this->projectKey = $config['projectKey'];
$this->projectKey = $issue['projectKey'];
$this->tagPrefix = $issue['tagPrefix'];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Service/Registrar/JIRA/JiraRegistrarFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class JiraRegistrarFactory implements RegistrarFactoryInterface
{
public function create(array $config): RegistrarInterface
{
$issueConfig = ($config['issue'] ?? []) + ['projectKey' => $config['projectKey']];
return new JiraRegistrar(
new IssueFieldFactory(new IssueConfig($config)),
new IssueFieldFactory(new IssueConfig($issueConfig)),
$this->createIssueService($config['service']),
);
}
Expand Down
15 changes: 7 additions & 8 deletions tests/Unit/Service/Registrar/IssueConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ final class IssueConfigTest extends TestCase
public function testValueAssigning(): void
{
$values = [
'issue' => [
'addTagToLabels' => true,
'components' => ['Component-1', 'Component-2'],
'labels' => ['Label-1', 'Label-2'],
'priority' => 'Low',
'tagPrefix' => 'tag-',
'type' => 'Bug',
],
'addTagToLabels' => true,
'components' => ['Component-1', 'Component-2'],
'labels' => ['Label-1', 'Label-2'],
'priority' => 'Low',
'tagPrefix' => 'tag-',
'type' => 'Bug',
// extra key added in factory
'projectKey' => 'Todo',
];
$config = new IssueConfig($values);
Expand Down

0 comments on commit 2371182

Please sign in to comment.