Completed
Push — master ( d83206...aa4419 )
by Marco
10s
created

fromRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
nc 1
nop 1
dl 0
loc 12
c 0
b 0
f 0
cc 1
rs 9.4285
1
<?php
2
declare(strict_types=1);
3
4
namespace Roave\ApiCompare\Git;
5
6
use Symfony\Component\Process\Process;
7
use Version\VersionsCollection;
8
9
final class GetVersionCollectionFromGitRepository implements GetVersionCollection
10
{
11
    /**
12
     * {@inheritDoc}
13
     * @throws \Symfony\Component\Process\Exception\ProcessFailedException
14
     * @throws \Symfony\Component\Process\Exception\LogicException
15
     * @throws \Symfony\Component\Process\Exception\RuntimeException
16
     */
17
    public function fromRepository(CheckedOutRepository $checkedOutRepository) : VersionsCollection
18
    {
19
        $output = (new Process(['git', 'tag', '-l']))
20
            ->setWorkingDirectory((string)$checkedOutRepository)
21
            ->mustRun()
22
            ->getOutput();
23
24
        // @todo handle invalid versions more gracefully (drop them)
25
        return VersionsCollection::fromArray(array_filter(
26
            explode("\n", $output),
27
            function (string $maybeVersion) {
28
                return trim($maybeVersion) !== '';
29
            }
30
        ));
31
    }
32
}
33