• 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

100.0
/src/EventListener/InitializeRepositoryListener.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\EventListener;
25

26
use Composer\IO;
27
use CPSIT\ProjectBuilder;
28
use EliasHaeussler\ComposerPackageTemplate\Enums;
29
use EliasHaeussler\ComposerPackageTemplate\Service;
30
use EliasHaeussler\ComposerPackageTemplate\ValueObject;
31

32
/**
33
 * InitializeRepositoryListener.
34
 *
35
 * @author Elias Häußler <elias@haeussler.dev>
36
 * @license GPL-3.0-or-later
37
 */
38
final class InitializeRepositoryListener
39
{
40
    public function __construct(
6✔
41
        private readonly Service\GitService $gitService,
42
        private readonly ProjectBuilder\IO\InputReader $inputReader,
43
        private readonly ProjectBuilder\IO\Messenger $messenger,
44
    ) {}
6✔
45

46
    public function __invoke(ProjectBuilder\Event\BuildStepProcessedEvent $event): void
6✔
47
    {
48
        $buildResult = $event->getBuildResult();
6✔
49

50
        if (!($event->getStep() instanceof ProjectBuilder\Builder\Generator\Step\MirrorProcessedFilesStep)) {
6✔
51
            return;
1✔
52
        }
53

54
        // Get repository data
55
        $repository = $buildResult->getInstructions()->getTemplateVariable('repository.createResult.object');
5✔
56
        $response = $buildResult->getInstructions()->getTemplateVariable('repository.createResult.response');
5✔
57

58
        if (!($repository instanceof ValueObject\GitHubRepository)
5✔
59
            || !($response instanceof Enums\CreateRepositoryResponse)
5✔
60
            || Enums\CreateRepositoryResponse::Failed === $response
5✔
61
            || !$this->gitService->isAvailable()
5✔
62
        ) {
63
            return;
3✔
64
        }
65

66
        // Remove repository data (since it's only necessary during runtime)
67
        $buildResult->getInstructions()->addTemplateVariable('repository.createResult', null);
2✔
68

69
        $this->messenger->newLine();
2✔
70

71
        if ($this->inputReader->ask('Should we initialize a local Git repository?')) {
2✔
72
            $this->messenger->progress('Initializing local repository...', IO\IOInterface::NORMAL);
1✔
73
            $this->gitService->initializeRepository($repository, $buildResult->getWrittenDirectory());
1✔
74
            $this->messenger->done();
1✔
75
        }
76
    }
77
}
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