Extractor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractNotification() 0 3 1
A getLines() 0 9 3
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