GitCommit   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Scriptura\QuickStart\Tasks;
6
7
use Scriptura\QuickStart\CommandRunner;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class GitCommit
12
{
13
    /**
14
     * @var string
15
     */
16
    private $commitMessage;
17
18
    public function __construct(string $commitMessage)
19
    {
20
        $this->commitMessage = $commitMessage;
21
    }
22
23
    public function __invoke(string $name, InputInterface $input, OutputInterface $output)
24
    {
25
        $output->writeln('<info># New git commit [' . $this->commitMessage . ']...</info>');
26
27
        $directory = getcwd() . '/' . $name;
28
29
        $commands = [
30
            'git add .',
31
            'git commit -m "' . $this->commitMessage . '"',
32
        ];
33
34
        $runner = new CommandRunner($output, $directory);
35
        $isSuccessful = $runner->run($commands);
36
37
        if ($isSuccessful) {
38
            $output->writeln('<comment>Successully committed.</comment>');
39
        }
40
    }
41
}
42