split_segments()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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 30
    return string_split('#/#', $path);
0 ignored issues
show
Bug Best Practice introduced by
The expression return string_split('#/#', $path) returns an array which contains values of type array which are incompatible with the documented value type string.
Loading history...
13
}
14
15
/**
16
 * Splits the string into parts using regular expressions and returns nonempty parts.
17
 * @param string $pattern The pattern to use for splitting
18
 * @param string $subject The string to split
19
 * @return string[] Split parts from the string
20
 */
21
function string_split(string $pattern, string $subject): array
22
{
23 31
    $parts = preg_split($pattern, $subject, -1, \PREG_SPLIT_NO_EMPTY);
24
25 31
    if (!\is_array($parts) || preg_last_error() !== \PREG_NO_ERROR) {
26 1
        throw new \RuntimeException('Error splitting string');
27
    }
28
29 30
    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...
30
}
31