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

StringType::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\Type;
10
11
use ptlis\SerializedDataEditor\Parser\Token;
12
13
/**
14
 * Class representing a serialized string value.
15
 */
16
final class StringType implements Type
17
{
18
    /** @var string */
19
    private $value;
20
21
22 45
    public function __construct(string $value)
23
    {
24 45
        $this->value = $value;
25 45
    }
26
27 2
    public function get(): string
28
    {
29 2
        return $this->value;
30
    }
31
32 1
    public function set(string $value): void
33
    {
34 1
        $this->value = $value;
35 1
    }
36
37 10
    public function containsStringCount(string $searchTerm): int
38
    {
39 10
        return substr_count($this->value, $searchTerm);
40
    }
41
42 6
    public function replaceString(string $searchTerm, string $replaceTerm): void
43
    {
44 6
        $this->value = str_replace($searchTerm, $replaceTerm, $this->value);
45 6
    }
46
47 9
    public function __toString(): string
48
    {
49 9
        return Token::PREFIX_STRING . ':' . strlen($this->value) . ':"' . $this->value . '";';
50
    }
51
}