1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* File: WebapiReportManager.php |
6
|
|
|
* |
7
|
|
|
* @author Maciej Sławik <[email protected]> |
8
|
|
|
* Github: https://github.com/maciejslawik |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace MSlwk\ReactPhpPlayground\Model\Report; |
12
|
|
|
|
13
|
|
|
use MSlwk\ReactPhpPlayground\Api\Report\ReportGeneratorInterface; |
14
|
|
|
use MSlwk\ReactPhpPlayground\Api\Report\WebapiReportManagerInterface; |
15
|
|
|
use MSlwk\ReactPhpPlayground\Api\Report\ReportSenderInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class WebapiReportManager |
19
|
|
|
* @package MSlwk\ReactPhpPlayground\Model\Report |
20
|
|
|
*/ |
21
|
|
|
class WebapiReportManager implements WebapiReportManagerInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var ReportGeneratorInterface |
25
|
|
|
*/ |
26
|
|
|
private $reportGenerator; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ReportSenderInterface |
30
|
|
|
*/ |
31
|
|
|
private $reportSender; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* WebapiReportManager constructor. |
35
|
|
|
* @param ReportGeneratorInterface $reportGenerator |
36
|
|
|
* @param ReportSenderInterface $reportSender |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
ReportGeneratorInterface $reportGenerator, |
40
|
|
|
ReportSenderInterface $reportSender |
41
|
|
|
) { |
42
|
|
|
$this->reportGenerator = $reportGenerator; |
43
|
|
|
$this->reportSender = $reportSender; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param int[] $customerIds |
48
|
|
|
* @return string[] |
49
|
|
|
*/ |
50
|
|
|
public function generateAndSendReportForCustomers(array $customerIds): array |
51
|
|
|
{ |
52
|
|
|
$messages = []; |
53
|
|
View Code Duplication |
foreach ($customerIds as $customerId) { |
|
|
|
|
54
|
|
|
$report = $this->reportGenerator->generateReport($customerId); |
55
|
|
|
$this->reportSender->sendReport($report); |
56
|
|
|
$messages[] = "Reporting process finished for customer: {$customerId}\n"; |
57
|
|
|
} |
58
|
|
|
return $messages; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.