Utilities   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 48
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pregSplitArray() 0 16 4
A pregSplitFlatArray() 0 14 3
1
<?php
2
3
/**
4
 * GitElephant - An abstraction layer for git written in PHP
5
 * Copyright (C) 2013  Matteo Giachino
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
19
 */
20
21
declare(strict_types=1);
22
23
namespace GitElephant;
24
25
/**
26
 * @author Matteo Giachino <[email protected]>
27
 */
28
class Utilities
29
{
30
    /**
31
     * explode an array by lines that match a regular expression
32
     *
33
     * @param string[] $list  a flat array
34
     * @param string $pattern a regular expression
35
     *
36
     * @return array<int, array<int, string>>
0 ignored issues
show
Documentation introduced by
The doc-type array<int, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
37
     */
38 4
    public static function pregSplitArray(array $list, string $pattern): array
39
    {
40 4
        $slices = [];
41 4
        $index = -1;
42 4
        foreach ($list as $value) {
43 4
            if (preg_match($pattern, $value) === 1) {
44 4
                ++$index;
45
            }
46
47 4
            if ($index !== -1) {
48 4
                $slices[$index][] = $value;
49
            }
50
        }
51
52 4
        return $slices;
53
    }
54
55
    /**
56
     * @param string[] $list  a flat array
57
     * @param string $pattern a regular expression
58
     *
59
     * @return array<int, array<int, string>>
0 ignored issues
show
Documentation introduced by
The doc-type array<int, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
60
     */
61 20
    public static function pregSplitFlatArray(array $list, string $pattern): array
62
    {
63 20
        $slices = [];
64 20
        $index = -1;
65 20
        foreach ($list as $value) {
66 20
            if (preg_match($pattern, $value) === 1) {
67 20
                ++$index;
68
            }
69
70 20
            $slices[$index + 1][] = $value;
71
        }
72
73 20
        return $slices;
74
    }
75
}
76