InvoiceCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 35
loc 35
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A createFromArray() 11 11 3
A getInvoices() 4 4 1

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
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Invoice;
6
7
use Billogram\Model\CreatableFromArray;
8
9
/**
10
 * @author Ibrahim Hizeoui <[email protected]>
11
 */
12 View Code Duplication
class InvoiceCollection implements CreatableFromArray
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
13
{
14
    /**
15
     * @var Invoice[]
16
     */
17
    private $invoices;
18
19
    /**
20
     * @param Invoice[] $invoices
21
     */
22 1
    private function __construct(array $invoices)
23
    {
24 1
        $this->invoices = $invoices;
25 1
    }
26
27 1
    public static function createFromArray(array $data)
28
    {
29 1
        $invoices = [];
30 1
        if (isset($data['data'])) {
31 1
            foreach ($data['data'] as $item) {
32 1
                $invoices[] = Invoice::createFromArray(['data' => $item]);
33
            }
34
        }
35
36 1
        return new self($invoices);
37
    }
38
39
    /**
40
     * @return Invoice[]
41
     */
42
    public function getInvoices()
43
    {
44
        return $this->invoices;
45
    }
46
}
47