Passed
Push — main ( 604bfc...f70419 )
by Sebastian
04:51
created

PostRewrite   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 31
rs 10
ccs 11
cts 11
cp 1
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromStdIn() 0 12 4
A getRanges() 0 3 1
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\Git\Range\Detector;
13
14
use CaptainHook\App\Console\IO;
15
use CaptainHook\App\Git\Range\Detecting;
16
use CaptainHook\App\Git\Range\Generic as Range;
17
use CaptainHook\App\Git\Rev\Generic as Rev;
18
19
/**
20
 * Class to access the pre-push stdIn data
21
 *
22
 * @package CaptainHook
23
 * @author  Sebastian Feldmann <[email protected]>
24
 * @link    https://github.com/captainhookphp/captainhook
25
 * @since   Class available since Release 5.15.0
26
 */
27
class PostRewrite implements Detecting
28
{
29
    /**
30
     * Returns list of refs
31
     *
32
     * @param  \CaptainHook\App\Console\IO $io
33
     * @return \CaptainHook\App\Git\Range[]
34
     */
35 1
    public function getRanges(IO $io): array
36
    {
37 1
        return $this->createFromStdIn($io->getStandardInput());
38
    }
39
40
    /**
41
     * Create ranges from stdIn
42
     *
43
     * @param  array<string> $stdIn
44
     * @return array<\CaptainHook\App\Git\Range>
45
     */
46 1
    private function createFromStdIn(array $stdIn): array
47
    {
48 1
        $ranges = [];
49 1
        foreach ($stdIn as $line) {
50 1
            if (!empty($line)) {
51 1
                $parts    = explode(' ', trim($line));
52 1
                $from     = new Rev(!empty($parts[1]) ? $parts[1] . '^' : 'HEAD@{1}');
53 1
                $to       = new Rev('HEAD');
54 1
                $ranges[] = new Range($from, $to);
55
            }
56
        }
57 1
        return $ranges;
58
    }
59
}
60