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

ArrayType::containsStringCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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\TypeFragment\ArrayElement;
12
13
/**
14
 * Class representing a serialized array value.
15
 */
16
final class ArrayType implements Type
17
{
18
    /** @var ArrayElement[] */
19
    private $elementList;
20
21
    /**
22
     * @param ArrayElement[] $elementList
23
     */
24 18
    public function __construct(array $elementList)
25
    {
26 18
        $this->elementList = $elementList;
27 18
    }
28
29 5
    public function containsStringCount(string $searchTerm): int
30
    {
31 5
        $count = 0;
32 5
        foreach ($this->elementList as $element) {
33 5
            $count += $element->containsStringCount($searchTerm);
34
        }
35 5
        return $count;
36
    }
37
38 3
    public function replaceString(string $searchTerm, string $replaceTerm): void
39
    {
40 3
        foreach ($this->elementList as $element) {
41 3
            $element->replaceString($searchTerm, $replaceTerm);
42
        }
43 3
    }
44
45 2
    public function __toString(): string
46
    {
47 2
        return 'a:' . count($this->elementList) . ':{' . join('', $this->elementList) . '}';
48
    }
49
}