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

ObjectDefaultSerializedType::replaceString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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\ObjectProperty;
12
13
/**
14
 * Class representing an object serialized with PHP's default object serializer.
15
 */
16
final class ObjectDefaultSerializedType implements Type
17
{
18
    /** @var string */
19
    private $className;
20
21
    /** @var ObjectProperty[] */
22
    private $propertyList;
23
24
    /**
25
     * @param string $className
26
     * @param ObjectProperty[] $propertyList
27
     */
28 15
    public function __construct(
29
        string $className,
30
        array $propertyList
31
    ) {
32 15
        $this->className = $className;
33 15
        $this->propertyList = $propertyList;
34 15
    }
35
36 5
    public function containsStringCount(string $searchTerm): int
37
    {
38 5
        $count = 0;
39 5
        foreach ($this->propertyList as $property) {
40 5
            $count += $property->containsStringCount($searchTerm);
41
        }
42 5
        return $count;
43
    }
44
45 3
    public function replaceString(string $searchTerm, string $replaceTerm): void
46
    {
47 3
        foreach ($this->propertyList as $property) {
48 3
            $property->replaceString($searchTerm, $replaceTerm);
49
        }
50 3
    }
51
52 2
    public function __toString(): string
53
    {
54 2
        return 'O:' . strlen($this->className) . ':"' . $this->className . '":' . count($this->propertyList) . ':{' . join('', $this->propertyList) . '}';
55
    }
56
}