Completed
Push — master ( 0dbd9d...4a0c8e )
by Shcherbak
01:27
created

SplittedStringList   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 34
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A all() 0 8 2
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