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

68publishers / tracy-git-version / 5982422976

26 Aug 2023 02:55AM UTC coverage: 90.041% (-2.2%) from 92.276%
5982422976

Pull #4

github

web-flow
Merge 0c60a3907 into fa82db0dd
Pull Request #4: Feature/git executable

465 of 465 new or added lines in 32 files covered. (100.0%)

434 of 482 relevant lines covered (90.04%)

0.9 hits per line

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

90.0
/src/Repository/ResolvableGitRepository.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\TracyGitVersion\Repository;
6

7
use SixtyEightPublishers\TracyGitVersion\Exception\BadMethodCallException;
8
use SixtyEightPublishers\TracyGitVersion\Exception\UnhandledCommandException;
9
use function get_class;
10

11
final class ResolvableGitRepository implements GitRepositoryInterface
12
{
13
    /** @var array<GitRepositoryInterface>  */
14
    private array $repositories;
15

16
    private bool $resolved = false;
17

18
    private ?GitRepositoryInterface $resolvedRepository = null;
19

20
    /**
21
     * @param array<GitRepositoryInterface> $repositories
22
     */
23
    public function __construct(array $repositories)
24
    {
25
        $this->repositories = (static fn (GitRepositoryInterface ...$repositories): array => $repositories)(...$repositories);
1✔
26
    }
1✔
27

28
    public function getSource(): string
29
    {
30
        $repository = $this->getResolvedRepository();
1✔
31

32
        return null !== $repository ? $repository->getSource() : 'unresolved';
1✔
33
    }
34

35
    public function isAccessible(): bool
36
    {
37
        $repository = $this->getResolvedRepository();
1✔
38

39
        return null !== $repository && $repository->isAccessible();
1✔
40
    }
41

42
    public function addHandler(string $commandClassname, GitCommandHandlerInterface $handler): void
43
    {
44
        throw BadMethodCallException::cantAddHandlerToResolvableGitRepository($commandClassname, get_class($handler));
×
45
    }
46

47
    public function handle(GitCommandInterface $command)
48
    {
49
        $repository = $this->getResolvedRepository();
1✔
50

51
        if (null === $repository) {
1✔
52
            throw UnhandledCommandException::cantHandleCommand($command);
×
53
        }
54

55
        return $repository->handle($command);
1✔
56
    }
57

58
    public function supports(string $commandClassname): bool
59
    {
60
        $repository = $this->getResolvedRepository();
1✔
61

62
        return null !== $repository && $repository->supports($commandClassname);
1✔
63
    }
64

65
    private function getResolvedRepository(): ?GitRepositoryInterface
66
    {
67
        if (false === $this->resolved) {
1✔
68
            foreach ($this->repositories as $repository) {
1✔
69
                if ($repository->isAccessible()) {
1✔
70
                    $this->resolvedRepository = $repository;
1✔
71

72
                    break;
1✔
73
                }
74
            }
75

76
            $this->resolved = true;
1✔
77
        }
78

79
        return $this->resolvedRepository;
1✔
80
    }
81
}
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