WebapiReportManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 12.5 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 5
loc 40
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A generateAndSendReportForCustomers() 5 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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