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

Text::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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