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

GitCheckoutRevisionToTemporaryPath   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkout() 0 8 1
A remove() 0 3 1
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