Extractor::getLines()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
rs 10
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Hook\Notify;
13
14
/**
15
 * Class Extractor
16
 *
17
 * @package CaptainHook
18
 * @author  Sebastian Feldmann <[email protected]>
19
 * @link    https://github.com/captainhook-git/captainhook
20
 * @since   Class available since Release 5.4.5
21
 */
22
class Extractor
23
{
24
    /**
25
     * Find the notification inside a commit message and return a Notification model
26
     *
27
     * @param  string $message
28
     * @param  string $prefix
29
     * @return \CaptainHook\App\Hook\Notify\Notification
30
     */
31 4
    public static function extractNotification(string $message, string $prefix = 'git-notify:'): Notification
32
    {
33 4
        return new Notification(self::getLines($message, $prefix));
34
    }
35
36
    /**
37
     * @param  string $message
38
     * @param  string $prefix
39
     * @return array<string>
40
     */
41 4
    private static function getLines(string $message, string $prefix): array
42
    {
43 4
        $matches = [];
44 4
        if (preg_match('#' . $prefix . '(.*)#is', $message, $matches)) {
45 3
            $split = preg_split("/\r\n|\n|\r/", $matches[1]);
46
47 3
            return is_array($split) ? array_map('trim', $split) : [];
0 ignored issues
show
introduced by
The condition is_array($split) is always true.
Loading history...
48
        }
49 1
        return [];
50
    }
51
}
52