CliReportManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 13.16 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 5
loc 38
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 8 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: CliReportManager.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\CliReportManagerInterface;
15
use MSlwk\ReactPhpPlayground\Api\Report\ReportSenderInterface;
16
17
/**
18
 * Class CliReportManager
19
 * @package MSlwk\ReactPhpPlayground\Model\Report
20
 */
21
class CliReportManager implements CliReportManagerInterface
22
{
23
    /**
24
     * @var ReportGeneratorInterface
25
     */
26
    private $reportGenerator;
27
28
    /**
29
     * @var ReportSenderInterface
30
     */
31
    private $reportSender;
32
33
    /**
34
     * CliReportManager 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 void
49
     */
50
    public function generateAndSendReportForCustomers(array $customerIds): void
51
    {
52 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...
53
            $report = $this->reportGenerator->generateReport($customerId);
54
            $this->reportSender->sendReport($report);
55
            echo "Reporting process finished for customer: {$customerId}\n";
56
        }
57
    }
58
}
59