Editor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
cbo 3
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A containsCount() 0 9 1
A replace() 0 11 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * @copyright   (c) 2017-present brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 */
8
9
namespace ptlis\SerializedDataEditor;
10
11
use ptlis\SerializedDataEditor\Parser\Parser;
12
use ptlis\SerializedDataEditor\Parser\Token;
13
use ptlis\SerializedDataEditor\Parser\Tokenizer;
14
15
/**
16
 * Allows editing of serialized datastructures.
17
 */
18
final class Editor
19
{
20 2
    public function containsCount(
21
        string $serializedData,
22
        string $searchTerm
23
    ): int {
24 2
        $tokenList = (new Tokenizer())->tokenize($serializedData);
25 2
        $type = (new Parser())->parse($tokenList);
26
27 2
        return $type->containsStringCount($searchTerm);
28
    }
29
30 1
    public function replace(
31
        string $serializedData,
32
        string $searchTerm,
33
        string $replaceTerm
34
    ): string {
35 1
        $tokenList = (new Tokenizer())->tokenize($serializedData);
36 1
        $type = (new Parser())->parse($tokenList);
37 1
        $type->replaceString($searchTerm, $replaceTerm);
38
39 1
        return strval($type);
40
    }
41
}