Passed
Push — master ( 1b968b...2baf19 )
by Philippe
01:56
created

Text::getEncoding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSpellcheck;
6
7
use PhpSpellcheck\Exception\InvalidArgumentException;
8
use Symfony\Component\String\UnicodeString;
9
10
class Text extends UnicodeString implements TextInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $context;
16
17
    public static function create(string $content, array $context = []): Text
18
    {
19
        return (new self($content))->setContext($context);
20
    }
21
22
    public function setContext(array $context): self
23
    {
24
        $this->context = $context;
25
26
        return $this;
27 36
    }
28
29 36
    public function getContent(): string
30 36
    {
31 36
        return (string) $this->string;
32 36
    }
33
34 31
    public function getContext(): array
35
    {
36 31
        return $this->context;
37
    }
38
39 4
    public function replaceContent(string $newContent): TextInterface
40
    {
41 4
        return self::create($newContent, $this->context);
42
    }
43
44 31
    public function mergeContext(array $context, bool $override = true): TextInterface
45
    {
46 31
        if (empty($context)) {
47
            throw new InvalidArgumentException('Context trying to be merged is empty');
48
        }
49 3
50
        return self::create(
51 3
            $this->getContent(),
52 1
            $override ? array_merge($this->getContext(), $context) : array_merge($context, $this->getContext())
53
        );
54
    }
55
}
56