Text::getContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
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<mixed>
11
     */
12
    private $context;
13
14
    /**
15
     * @var string
16
     */
17
    private $string;
18
19
    /**
20
     * @param array<mixed> $context
21
     */
22
    public function __construct(string $string, array $context)
23
    {
24
        $this->string = $string;
25
        $this->context = $context;
26
    }
27 36
28
    /**
29 36
     * @param array<mixed> $context
30 36
     */
31 36
    public function setContext(array $context): self
32 36
    {
33
        $this->context = $context;
34 31
35
        return $this;
36 31
    }
37
38
    public function getContent(): string
39 4
    {
40
        return $this->string;
41 4
    }
42
43
    public function getContext(): array
44 31
    {
45
        return $this->context;
46 31
    }
47
48
    public function replaceContent(string $newContent): TextInterface
49 3
    {
50
        return new self($newContent, $this->context);
51 3
    }
52 1
53
    public function mergeContext(array $context, bool $override = true): TextInterface
54
    {
55 2
        return new self(
56 2
            $this->getContent(),
57 2
            $override ? array_merge($this->getContext(), $context) : array_merge($context, $this->getContext())
58 2
        );
59
    }
60
}
61