Skip to content

Commit 7939f94

Browse files
authored
refactor: remove tightly coupled template parser from report client (#36)
1 parent 9ce5787 commit 7939f94

File tree

10 files changed

+16
-22
lines changed

10 files changed

+16
-22
lines changed

lib/Client/BitbucketReport.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use KirbyReporter\Model\FormData;
66
use KirbyReporter\Report\ReportInterface;
77
use KirbyReporter\Report\ReportResponse;
8-
use KirbyReporter\Report\ReportTemplateParser;
98
use KirbyReporter\Traits\Expander;
109
use KirbyReporter\Traits\Request;
1110
use KirbyReporter\Vendor\Vendor;
@@ -14,7 +13,6 @@ class BitbucketReport implements ReportInterface
1413
{
1514
use Request;
1615
use Expander;
17-
use ReportTemplateParser;
1816

1917
private string $urlTemplate = "https://api.bitbucket.org/2.0/repositories/{user}/{repo}/issues";
2018

@@ -25,7 +23,7 @@ public function __construct(Vendor $vendor)
2523
$this->vendor = $vendor;
2624
}
2725

28-
public final function report(FormData $reportData): ReportResponse
26+
public final function report(FormData $reportData, string $parsedTemplate): ReportResponse
2927
{
3028
$url = $this->expandUrl($this->urlTemplate, [
3129
"user" => $this->vendor->getOwner(),
@@ -34,7 +32,7 @@ public final function report(FormData $reportData): ReportResponse
3432

3533
$reportData = [
3634
"title" => $reportData->getTitle(),
37-
"description" => $this->parseTemplate($reportData->getFormFields()),
35+
"description" => $parsedTemplate,
3836
];
3937

4038
$header = ["Authorization" => "Basic ".$this->getBasicAuth()];

lib/Client/GithubReport.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use KirbyReporter\Model\FormData;
66
use KirbyReporter\Report\ReportInterface;
77
use KirbyReporter\Report\ReportResponse;
8-
use KirbyReporter\Report\ReportTemplateParser;
98
use KirbyReporter\Traits\Expander;
109
use KirbyReporter\Traits\Request;
1110
use KirbyReporter\Vendor\Vendor;
@@ -14,7 +13,6 @@ class GithubReport implements ReportInterface
1413
{
1514
use Request;
1615
use Expander;
17-
use ReportTemplateParser;
1816

1917
private string $urlTemplate = "https://api.github.com/repos/{user}/{repo}/issues";
2018

@@ -25,7 +23,7 @@ public function __construct(Vendor $vendor)
2523
$this->vendor = $vendor;
2624
}
2725

28-
public final function report(FormData $reportData): ReportResponse
26+
public final function report(FormData $reportData, string $parsedTemplate): ReportResponse
2927
{
3028
$url = $this->expandUrl($this->urlTemplate, [
3129
"user" => $this->vendor->getOwner(),
@@ -34,7 +32,7 @@ public final function report(FormData $reportData): ReportResponse
3432

3533
$reportData = [
3634
"title" => $reportData->getTitle(),
37-
"body" => $this->parseTemplate($reportData->getFormFields()),
35+
"body" => $parsedTemplate,
3836
];
3937

4038
$header = ["Authorization" => "token ".$this->vendor->getToken()];

lib/Client/GitlabReport.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use KirbyReporter\Model\FormData;
66
use KirbyReporter\Report\ReportInterface;
77
use KirbyReporter\Report\ReportResponse;
8-
use KirbyReporter\Report\ReportTemplateParser;
98
use KirbyReporter\Traits\Expander;
109
use KirbyReporter\Traits\Request;
1110
use KirbyReporter\Vendor\Vendor;
@@ -14,7 +13,6 @@ class GitlabReport implements ReportInterface
1413
{
1514
use Request;
1615
use Expander;
17-
use ReportTemplateParser;
1816

1917
private string $urlTemplate = "https://gitlab.com/api/v4/projects/{user}%2F{repo}/issues";
2018

@@ -25,7 +23,7 @@ public function __construct(Vendor $vendor)
2523
$this->vendor = $vendor;
2624
}
2725

28-
public final function report(FormData $reportData): ReportResponse
26+
public final function report(FormData $reportData, string $parsedTemplate): ReportResponse
2927
{
3028
$url = $this->expandUrl($this->urlTemplate, [
3129
"user" => $this->vendor->getOwner(),
@@ -34,7 +32,7 @@ public final function report(FormData $reportData): ReportResponse
3432

3533
$reportData = [
3634
"title" => $reportData->getTitle(),
37-
"description" => $this->parseTemplate($reportData->getFormFields()),
35+
"description" => $parsedTemplate,
3836
];
3937

4038
$header = ["Private-Token" => $this->vendor->getToken()];

lib/Report/ReportClient.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
class ReportClient
1818
{
19+
use ReportTemplateParser;
20+
1921
/**
2022
* @var BitbucketReport|GithubReport|GitlabReport
2123
*/
@@ -38,6 +40,8 @@ public function __construct(Vendor $vendor)
3840

3941
public final function createReport(FormData $formData): ReportResponse
4042
{
41-
return $this->client->report($formData);
43+
$parsedTemplate = $this->parseTemplate($formData->getFormFields());
44+
45+
return $this->client->report($formData, $parsedTemplate);
4246
}
4347
}

lib/Report/ReportInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
*/
1111
interface ReportInterface
1212
{
13-
public function report(FormData $reportData): ReportResponse;
13+
public function report(FormData $reportData, string $parsedTemplate): ReportResponse;
1414
}

tests/Client/BitbucketReportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function test_should_send_form_data_to_bitbucket_api()
5050
'description' => 'Test',
5151
],
5252
]);
53-
$response = $reporter->report($formData);
53+
$response = $reporter->report($formData, 'parsedTemplate');
5454

5555
// request
5656
$this->assertEquals("/2.0/repositories/test/test-repo/issues", $mock->getLastRequest()->getUri()->getPath());

tests/Client/GithubReportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function test_should_send_form_data_to_gitlab_api()
4343
'description' => 'Test',
4444
],
4545
]);
46-
$response = $reporter->report($formData);
46+
$response = $reporter->report($formData, 'parsedTemplate');
4747

4848
// request
4949
$this->assertEquals("/repos/test/test-repo/issues", $mock->getLastRequest()->getUri()->getPath());

tests/Client/GitlabReportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function test_should_send_form_data_to_gitlab_api()
4343
'description' => 'Test',
4444
],
4545
]);
46-
$response = $reporter->report($formData);
46+
$response = $reporter->report($formData, 'parsedTemplate');
4747

4848
// request
4949
$this->assertEquals("/api/v4/projects/test%2Ftest-repo/issues", $mock->getLastRequest()->getUri()->getPath());

tests/Report/ReportClientTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @noinspection MethodShouldBeFinalInspection
55
*/
66

7-
namespace KirbyReporter\Mixins;
8-
97
use GuzzleHttp\Client;
108
use GuzzleHttp\Handler\MockHandler;
119
use GuzzleHttp\HandlerStack;
@@ -98,7 +96,7 @@ private function test_exeption(int $code, string $message)
9896
$this->expectExceptionMessage($message);
9997
$this->expectExceptionCode($code);
10098

101-
$reporter->report($formData);
99+
$reporter->report($formData, 'parsedTemplate');
102100
}
103101
}
104102

tests/Vendor/VendorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @noinspection MethodShouldBeFinalInspection
55
*/
66

7-
namespace KirbyReporter\Mixins;
8-
97
use KirbyReporter\Exception\OptionNotFoundException;
108
use KirbyReporter\Exception\UnsupportedPlatformException;
119
use KirbyReporter\Vendor\Vendor;

0 commit comments

Comments
 (0)