SetVersion   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 22 3
1
<?php
2
3
namespace Squadron\Base\Console\Commands;
4
5
use Illuminate\Console\Command;
6
7
class SetVersion extends Command
8
{
9
    protected $signature = 'squadron:version:set';
10
    protected $description = 'Set version in .env (from git last commit)';
11
12
    /**
13
     * Execute the console command.
14
     */
15
    public function handle(): void
16
    {
17
        $commitMessage = trim(exec('git log --pretty="%s" -n1 HEAD'));
18
19
        if (preg_match('#Merge branch \'release/(.*?)\'#is', $commitMessage, $matches))
20
        {
21
            $version = $matches[1];
22
23
            if (! empty($version))
24
            {
25
                $envFilePath = base_path('/.env');
26
                $envFileData = file_get_contents($envFilePath);
27
28
                $envFileData = preg_replace(
29
                    '#^APP_VERSION=(.*?)$#im',
30
                    sprintf('APP_VERSION=%s', $version),
31
                    $envFileData
32
                );
33
34
                file_put_contents($envFilePath, $envFileData);
35
36
                $this->info(sprintf('Set APP version: %s', $version));
37
            }
38
        }
39
    }
40
}
41