• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / composer-package-template / 12861990819

20 Jan 2025 01:05AM UTC coverage: 99.502%. Remained the same
12861990819

push

github

web-flow
[TASK] Update all dependencies

400 of 402 relevant lines covered (99.5%)

3.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/Service/GitService.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/composer-package-template".
7
 *
8
 * Copyright (C) 2023-2025 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\ComposerPackageTemplate\Service;
25

26
use EliasHaeussler\ComposerPackageTemplate\Enums;
27
use EliasHaeussler\ComposerPackageTemplate\Resource;
28
use EliasHaeussler\ComposerPackageTemplate\ValueObject;
29

30
use function sprintf;
31
use function trim;
32

33
/**
34
 * GitService.
35
 *
36
 * @author Elias Häußler <elias@haeussler.dev>
37
 * @license GPL-3.0-or-later
38
 */
39
final class GitService
40
{
41
    public function __construct(
4✔
42
        private readonly Resource\ProcessFactory $processFactory,
43
    ) {}
4✔
44

45
    public function initializeRepository(
2✔
46
        ValueObject\GitHubRepository $repository,
47
        string $directory,
48
    ): Enums\InitializeRepositoryResponse {
49
        // Initialize repository
50
        $initProcess = $this->processFactory->create(['git', 'init', '--initial-branch', 'main']);
2✔
51
        $initProcess->setWorkingDirectory($directory);
2✔
52
        $initProcess->run();
2✔
53

54
        // Early return if repository could not be initialized
55
        if (!$initProcess->isSuccessful()) {
2✔
56
            return Enums\InitializeRepositoryResponse::Failed;
1✔
57
        }
58

59
        // Add remote repository
60
        $remoteUrl = sprintf(
1✔
61
            'git@%s:%s.git',
1✔
62
            $repository->getUrl()->getHost(),
1✔
63
            trim($repository->getUrl()->getPath(), '/'),
1✔
64
        );
1✔
65
        $remoteProcess = $this->processFactory->create([
1✔
66
            'git',
1✔
67
            'remote',
1✔
68
            'add',
1✔
69
            'origin',
1✔
70
            $remoteUrl,
1✔
71
        ]);
1✔
72
        $remoteProcess->setWorkingDirectory($directory);
1✔
73
        $remoteProcess->run();
1✔
74

75
        if ($remoteProcess->isSuccessful()) {
1✔
76
            return Enums\InitializeRepositoryResponse::Initialized;
1✔
77
        }
78

79
        return Enums\InitializeRepositoryResponse::Failed;
×
80
    }
81

82
    public function isAvailable(): bool
2✔
83
    {
84
        return $this->processFactory->isExecutable('git');
2✔
85
    }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc