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

Spreadsheet::replace()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
crap 2
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