iterable_concat()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 4
nop 2
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved;
6
7
/**
8
 * Concatenate all elements into a single string.
9
 *
10
 * @param iterable $iterable
11
 * @param string   $glue
12
 * @return string
13
 */
14
function iterable_concat(iterable $iterable, string $glue = ''): string
0 ignored issues
show
introduced by
Function Improved\iterable_concat() has parameter $iterable with no value type specified in iterable type iterable.
Loading history...
15
{
16 9
    $string = "";
17
18 9
    foreach ($iterable as $item) {
19 8
        $string .= $item . $glue;
20
    }
21
22 9
    return $glue === "" ? $string : substr($string, 0, -1 * strlen($glue));
23
}
24