Completed
Pull Request — master (#15)
by James
02:25
created

GitCheckoutRevisionToTemporaryPath::checkout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Roave\ApiCompare\Git;
5
6
use Symfony\Component\Process\Process;
7
8
final class GitCheckoutRevisionToTemporaryPath implements PerformCheckoutOfRevision
9
{
10
    /**
11
     * {@inheritDoc}
12
     * @throws \Symfony\Component\Process\Exception\RuntimeException
13
     */
14
    public function checkout(CheckedOutRepository $sourceRepository, Revision $revision) : CheckedOutRepository
15
    {
16
        $checkoutDirectory = sys_get_temp_dir() . '/api-compare-' . (string)$revision;
17
18
        (new Process(['git', 'clone', (string)$sourceRepository, $checkoutDirectory]))->mustRun();
19
        (new Process(['git', 'checkout', (string)$revision]))->setWorkingDirectory($checkoutDirectory)->mustRun();
20
21
        return CheckedOutRepository::fromPath($checkoutDirectory);
22
    }
23
24
    /**
25
     * {@inheritDoc}
26
     * @throws \Symfony\Component\Process\Exception\RuntimeException
27
     */
28
    public function remove(CheckedOutRepository $checkedOutRepository) : void
29
    {
30
        (new Process(['rm', '-rf', (string)$checkedOutRepository]))->mustRun();
31
    }
32
}
33