dlindberg /
BlobChunk
| 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
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 |