Completed
Push — develop ( 6acb11...b743df )
by Baptiste
05:00
created

Spreadsheet   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 43.75 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 28
loc 64
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A name() 0 4 1
A sheets() 0 4 1
A add() 14 14 2
A replace() 14 14 2
A has() 0 4 1
A get() 0 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
declare(strict_types = 1);
3
4
namespace Spreadsheet;
5
6
use Spreadsheet\Exception\{
7
    SheetAlreadyExistsException,
8
    SheetNotFoundException
9
};
10
use Innmind\Immutable\{
11
    MapInterface,
12
    Map
13
};
14
15
final class Spreadsheet implements SpreadsheetInterface
16
{
17
    private $name;
18
    private $sheets;
19
20 5
    public function __construct(string $name)
21
    {
22 5
        $this->name = $name;
23 5
        $this->sheets = new Map('string', SheetInterface::class);
24 5
    }
25
26 3
    public function name(): string
27
    {
28 3
        return $this->name;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public function sheets(): MapInterface
35
    {
36 1
        return $this->sheets;
37
    }
38
39 3 View Code Duplication
    public function add(SheetInterface $sheet): SpreadsheetInterface
1 ignored issue
show
Duplication introduced by
This method 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...
40
    {
41 3
        if ($this->has($sheet->name())) {
42 1
            throw new SheetAlreadyExistsException;
43
        }
44
45 3
        $self = new self($this->name);
46 3
        $self->sheets = $this->sheets->put(
47 3
            $sheet->name(),
48
            $sheet
49
        );
50
51 3
        return $self;
52
    }
53
54 2 View Code Duplication
    public function replace(SheetInterface $sheet): SpreadsheetInterface
1 ignored issue
show
Duplication introduced by
This method 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...
55
    {
56 2
        if (!$this->has($sheet->name())) {
57 1
            throw new SheetNotFoundException;
58
        }
59
60 1
        $self = new self($this->name);
61 1
        $self->sheets = $this->sheets->put(
62 1
            $sheet->name(),
63
            $sheet
64
        );
65
66 1
        return $self;
67
    }
68
69 4
    public function has(string $sheet): bool
70
    {
71 4
        return $this->sheets->contains($sheet);
72
    }
73
74 1
    public function get(string $sheet): SheetInterface
75
    {
76 1
        return $this->sheets->get($sheet);
77
    }
78
}
79