Text   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
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 51
ccs 17
cts 17
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<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