SplitChunk::doSplit()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace dlindberg\BlobChunk\Parser;
6
7
final class SplitChunk extends BaseParser implements Parse
8
{
9
10
    public function parse(\DOMElement $input): array
11
    {
12
        $strings[] = $this->stringify($input);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$strings was never initialized. Although not strictly required by PHP, it is generally a good practice to add $strings = array(); before regardless.
Loading history...
13
14
        return $this->blowItUp($this->manager->getSplitNodeDelimiters(), $strings);
15
    }
16
17
    private function blowItUp(array $delimiters, array $strings): array
18
    {
19
        $delimiter = \array_shift($delimiters);
20
        $strings = \array_merge(...\array_map(function (string $string) use ($delimiter): array {
21
            return $this->doSplit($delimiter, $string);
22
        }, $strings));
23
24
        return 0 === \count($delimiters) ? $strings : $this->blowItUp($delimiters, $strings);
25
    }
26
27
    private function doSplit(string $delimiter, string $string): array
28
    {
29
        return \array_map(function ($part) use ($delimiter): string {
30
            return !\in_array(substr($part, -1), \array_merge(['>'], $this->manager->getSplitNodeDelimiters(true))) ?
31
                $part . \trim($delimiter) : $part;
32
        }, \explode($delimiter, $string));
33
    }
34
}
35