SplittedStringList::all()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2.0185
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Funivan\CabbageCore\String\StringList\Splitted;
6
7
use Funivan\CabbageCore\String\StringList\StringListInterface;
8
9
class SplittedStringList implements StringListInterface
10
{
11
12
13
    /**
14
     * @var string
15
     */
16
    private $pattern;
17
18
    /**
19
     * @var string
20
     */
21
    private $input;
22
23
24 1
    public function __construct(string $pattern, string $input)
25
    {
26 1
        $this->pattern = $pattern;
27 1
        $this->input = $input;
28 1
    }
29
30
31
    /**
32
     * @return string[]|\Generator
33
     */
34 1
    public function all(): \Generator
35
    {
36 1
        $result = preg_split($this->pattern, $this->input);
37 1
        if (!is_array($result)) {
38
            throw new \RuntimeException('Can not split string');
39
        }
40 1
        yield from $result;
41 1
    }
42
}
43