Completed
Push — master ( 4677f1...4b9138 )
by James
13s queued 10s
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
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\Git;
6
7
use Symfony\Component\Process\Exception\RuntimeException;
8
use Symfony\Component\Process\Process;
9
use function sys_get_temp_dir;
10
11
final class GitCheckoutRevisionToTemporaryPath implements PerformCheckoutOfRevision
12
{
13
    /**
14
     * {@inheritDoc}
15
     * @throws RuntimeException
16
     */
17
    public function checkout(CheckedOutRepository $sourceRepository, Revision $revision) : CheckedOutRepository
18
    {
19
        $checkoutDirectory = sys_get_temp_dir() . '/api-compare-' . (string) $revision;
20
21
        (new Process(['git', 'clone', (string) $sourceRepository, $checkoutDirectory]))->mustRun();
22
        (new Process(['git', 'checkout', (string) $revision]))->setWorkingDirectory($checkoutDirectory)->mustRun();
23
24
        return CheckedOutRepository::fromPath($checkoutDirectory);
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     * @throws RuntimeException
30
     */
31
    public function remove(CheckedOutRepository $checkedOutRepository) : void
32
    {
33
        (new Process(['rm', '-rf', (string) $checkedOutRepository]))->mustRun();
34
    }
35
}
36