Passed
Push — master ( ed3164...71916c )
by Petr
02:23
created

TSeparated::compactStr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_auth_sources\Traits;
4
5
6
use kalanis\kw_auth_sources\Interfaces\IFile;
7
8
9
/**
10
 * Trait TSeparated
11
 * @package kalanis\kw_auth_sources\Traits
12
 * Separate values in entry
13
 */
14
trait TSeparated
15
{
16
    /**
17
     * @param string $parent
18
     * @param string $separator
19
     * @return string[]
20
     */
21 7
    public function separateStr(string $parent, string $separator = IFile::PARENT_SEPARATOR): array
22
    {
23 7
        return array_values(
24 7
            array_filter(
25 7
                array_map(
26 7
                    'strval',
27 7
                    array_filter(
28 7
                        (array) explode(
29 7
                            $separator ?: IFile::PARENT_SEPARATOR, $parent
30
                        )
31
                    )
32
                )
33
            )
34
        );
35
    }
36
37
    /**
38
     * @param string[] $parent
39
     * @param string $separator
40
     * @return string
41
     */
42 5
    public function compactStr(array $parent, string $separator = IFile::PARENT_SEPARATOR): string
43
    {
44 5
        return implode($separator, array_values(array_filter(array_map('strval', $parent))));
45
    }
46
}
47