VersionControl::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php namespace Magestead\Service;
2
3
use Magestead\Command\ProcessCommand;
4
use Symfony\Component\Console\Output\OutputInterface;
5
6
class VersionControl
7
{
8
    protected $_output;
9
    protected $_repoUrl;
10
    protected $_projectPath;
11
12
    /**
13
     * VersionControl constructor.
14
     * @param $repoUrl
15
     * @param $projectPath
16
     * @param OutputInterface $output
17
     */
18
    public function __construct($repoUrl, $projectPath, OutputInterface $output)
19
    {
20
        $this->_output = $output;
21
        $this->_repoUrl = $repoUrl;
22
        $this->_projectPath = $projectPath;
23
24
        $this->execute($output);
25
    }
26
27
    /**
28
     * @param OutputInterface $output
29
     */
30
    protected function execute(OutputInterface $output)
31
    {
32
        $output->writeln('<info>Configuring GIT repo</info>');
33
        $this->init();
34
35
        $output->writeln('<comment>Adding files to repo</comment>');
36
        $this->addFiles();
37
38
        $output->writeln('<comment>Committing files to repo</comment>');
39
        $this->commitFiles();
40
    }
41
42
    /**
43
     * Initialise the GIT repo
44
     *
45
     * @return $this
46
     */
47
    public function init()
48
    {
49
        $command = 'git init; git remote add origin ' . $this->_repoUrl;
50
        new ProcessCommand($command, $this->_projectPath, $this->_output);
51
52
        return $this;
53
    }
54
55
    /**
56
     * Add all file to the GIT index
57
     *
58
     * @return $this
59
     */
60
    public function addFiles()
61
    {
62
        $command = 'git add -A';
63
        new ProcessCommand($command, $this->_projectPath, $this->_output);
64
65
        return $this;
66
    }
67
68
    /**
69
     * Commit the files to the repo
70
     *
71
     * @return $this
72
     */
73
    public function commitFiles()
74
    {
75
        $command = "git commit -m 'Initial commit'";
76
        new ProcessCommand($command, $this->_projectPath, $this->_output);
77
78
        return $this;
79
    }
80
81
    /**
82
     * Push all the files to remote repo
83
     *
84
     * @return $this
85
     */
86
    public function pushFiles()
87
    {
88
        $command = "git push -u origin master";
89
        new ProcessCommand($command, $this->_projectPath, $this->_output);
90
91
        return $this;
92
    }
93
}
94