Passed
Push — stable ( 4bc356...4bd7f3 )
by Nuno
04:37 queued 02:22
created

Providers/GitVersion/GitVersionServiceProvider.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Providers\GitVersion;
15
16
use Symfony\Component\Process\Process;
17
use Illuminate\Support\ServiceProvider;
18
use Illuminate\Contracts\Foundation\Application;
19
20
/**
21
 * @codeCoverageIgnore
22
 * @internal
23
 */
24
final class GitVersionServiceProvider extends ServiceProvider
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function register(): void
30
    {
31
        $this->app->bind(
32
            'git.version',
33
            function (Application $app) {
34
                $lastRevisionTag = '$(git rev-list --tags --max-count=1)';
35
36
                if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
37
                    $taskGetLastRevisionTag = 'git rev-list --tags --max-count=1';
38
39
                    $process = tap(new Process($taskGetLastRevisionTag, $app->basePath()))->run();
0 ignored issues
show
$taskGetLastRevisionTag of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
                    $process = tap(new Process(/** @scrutinizer ignore-type */ $taskGetLastRevisionTag, $app->basePath()))->run();
Loading history...
40
41
                    $lastRevisionTag = trim($process->getOutput()) ?: 'unreleased';
42
43
                    if ($lastRevisionTag === 'unreleased') {
44
                        return 'unreleased';
45
                    }
46
                }
47
                $task = "git describe --tags $lastRevisionTag";
48
49
                $process = tap(new Process($task, $app->basePath()))->run();
50
51
                return trim($process->getOutput()) ?: 'unreleased';
52
            }
53
        );
54
    }
55
}
56