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

PostRewrite::getRanges()   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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 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