GitCommit::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 16
rs 9.9666
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