Passed
Push — master ( 641f51...6308bb )
by Philippe
01:41
created

Text   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 45
ccs 13
cts 13
cp 1
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getContext() 0 3 1
A getContent() 0 3 1
A mergeContext() 0 5 2
A setContext() 0 5 1
A __construct() 0 4 1
A replaceContent() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSpellcheck;
6
7
class Text implements TextInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $context;
13
14
    /**
15
     * @var string
16
     */
17
    private $string;
18
19
    public function __construct(string $string, array $context)
20
    {
21
        $this->string = $string;
22
        $this->context = $context;
23
    }
24
25
    public function setContext(array $context): self
26
    {
27 36
        $this->context = $context;
28
29 36
        return $this;
30 36
    }
31 36
32 36
    public function getContent(): string
33
    {
34 31
        return $this->string;
35
    }
36 31
37
    public function getContext(): array
38
    {
39 4
        return $this->context;
40
    }
41 4
42
    public function replaceContent(string $newContent): TextInterface
43
    {
44 31
        return new self($newContent, $this->context);
45
    }
46 31
47
    public function mergeContext(array $context, bool $override = true): TextInterface
48
    {
49 3
        return new self(
50
            $this->getContent(),
51 3
            $override ? array_merge($this->getContext(), $context) : array_merge($context, $this->getContext())
52 1
        );
53
    }
54
}
55