Completed
Push — master ( 9017a1...3ff80b )
by Tomáš
04:23
created

pushDirectoryContentToRepository()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0393

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 11
cts 14
cp 0.7856
rs 9.2
c 0
b 0
f 0
cc 2
eloc 14
nc 2
nop 2
crap 2.0393
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Github;
11
12
use GitWrapper\GitWrapper;
13
use Symplify\PHP7_Sculpin\Utils\FilesystemChecker;
14
15
final class GihubPublishingProcess
16
{
17
    /**
18
     * @var string
19
     */
20
    const CONFIG_EMAIL = '[email protected]';
21
22
    /**
23
     * @var string
24
     */
25
    const CONFIG_NAME = 'Travis';
26
27 2
    public function pushDirectoryContentToRepository(string $outputDirectory, string $githubRepository)
28
    {
29 2
        FilesystemChecker::ensureDirectoryExists($outputDirectory);
30
31 1
        $git = (new GitWrapper())->init($outputDirectory);
32
33 1
        if (getenv('TRAVIS')) {
34 1
            $git->config('user.email', self::CONFIG_EMAIL);
35 1
            $git->config('user.name', self::CONFIG_NAME);
36
        }
37
38 1
        $git->checkout('gh-pages', [
39 1
            'orphan' => true,
40
        ]);
41 1
        $git->add('.');
42 1
        $git->commit('Regenerate output');
43 1
        $git->addRemote('origin', $githubRepository);
44
        $git->push('origin', 'gh-pages', [
45
            'force' => true,
46
            'quiet' => true,
47
        ]);
48
    }
49
}
50