Completed
Push — master ( ceed61...62539f )
by Riikka
03:18
created

string_split()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 4
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Simply\Router;
4
5
/**
6
 * Splits the given path into nonempty segments.
7
 * @param string $path The path to split
8
 * @return string[] The non empty segments from the path
9
 */
10
function split_segments(string $path): array
11
{
12 24
    return string_split('#/#', $path, -1, \PREG_SPLIT_NO_EMPTY);
13
}
14
15
/**
16
 * Splits the string into parts using regular expressions.
17
 * @param string $pattern The pattern to use for splitting
18
 * @param string $subject The string to split
19
 * @param int $limit Maximum number of parts or -1 for unlimited
20
 * @param int $flags The flags for the preg_split
21
 * @return string[] Split parts from the string
22
 */
23
function string_split(string $pattern, string $subject, int $limit = -1, int $flags = 0): array
24
{
25 25
    $parts = preg_split($pattern, $subject, $limit, $flags);
26
27 25
    if (!\is_array($parts) || preg_last_error() !== \PREG_NO_ERROR) {
28 1
        throw new \RuntimeException('Error splitting string');
29
    }
30
31 24
    return $parts;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $parts returns an array which contains values of type array which are incompatible with the documented value type string.
Loading history...
32
}
33