SplittedStringList::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
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