Completed
Push — master ( 3d13bd...bc1124 )
by brian
01:41
created

ArrayElementStringIndex::replaceString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * @copyright   (c) 2019-present brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 */
8
9
namespace ptlis\SerializedDataEditor\TypeFragment;
10
11
use ptlis\SerializedDataEditor\Parser\Token;
12
use ptlis\SerializedDataEditor\Type\Type;
13
14
/**
15
 * Class representing a single element in an array, indexed by a string.
16
 */
17
final class ArrayElementStringIndex implements ArrayElement
18
{
19
    /** @var string */
20
    private $index;
21
22
    /** @var Type */
23
    private $value;
24
25
26 11
    public function __construct(string $index, Type $value)
27
    {
28 11
        $this->index = $index;
29 11
        $this->value = $value;
30 11
    }
31
32 1
    public function getIndex(): string
33
    {
34 1
        return $this->index;
35
    }
36
37 1
    public function setIndex(string $index): void
38
    {
39 1
        $this->index = $index;
40 1
    }
41
42 1
    public function getValue(): Type
43
    {
44 1
        return $this->value;
45
    }
46
47 1
    public function setValue(Type $value): void
48
    {
49 1
        $this->value = $value;
50 1
    }
51
52 3
    public function containsStringCount(string $searchTerm): int
53
    {
54 3
        return $this->value->containsStringCount($searchTerm);
55
    }
56
57 2
    public function replaceString(string $searchTerm, string $replaceTerm): void
58
    {
59 2
        $this->value->replaceString($searchTerm, $replaceTerm);
60 2
    }
61
62 2
    public function __toString(): string
63
    {
64 2
        return Token::PREFIX_STRING . ':' . strlen($this->index) . ':"' . $this->index . '";' . $this->value;
65
    }
66
}