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

68publishers / tracy-git-version / 3672506103

pending completion
3672506103

Pull #3

github

GitHub
Merge 8b6464ed0 into 50bf69527
Pull Request #3: Ci and static analysis

97 of 97 new or added lines in 21 files covered. (100.0%)

454 of 492 relevant lines covered (92.28%)

0.92 hits per line

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

90.91
/src/Repository/LocalDirectory/CommandHandler/GetHeadCommandHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\TracyGitVersion\Repository\LocalDirectory\CommandHandler;
6

7
use SixtyEightPublishers\TracyGitVersion\Repository\Entity\Head;
8
use SixtyEightPublishers\TracyGitVersion\Repository\Entity\CommitHash;
9
use SixtyEightPublishers\TracyGitVersion\Repository\Command\GetHeadCommand;
10
use function trim;
11
use function strlen;
12
use function strpos;
13
use function substr;
14
use function explode;
15
use function is_readable;
16
use function file_get_contents;
17

18
final class GetHeadCommandHandler extends AbstractLocalDirectoryCommandHandler
19
{
20
        /**
21
         * @throws \SixtyEightPublishers\TracyGitVersion\Exception\GitDirectoryException
22
         */
23
        public function __invoke(GetHeadCommand $command): Head
1✔
24
        {
25
                $headFile = $this->getGitDirectory() . DIRECTORY_SEPARATOR . 'HEAD';
1✔
26

27
                # not versioned
28
                if (!is_readable($headFile) || false === ($content = @file_get_contents($headFile))) {
1✔
29
                        return new Head(null, null);
×
30
                }
31

32
                # detached head
33
                if (0 !== strpos($content, 'ref:')) {
1✔
34
                        return new Head(null, new CommitHash(trim($content)));
1✔
35
                }
36

37
                $branchParts = explode('/', $content, 3);
1✔
38
                $commitFile = $this->getGitDirectory() . DIRECTORY_SEPARATOR . trim(substr($content, 5, strlen($content)));
1✔
39

40
                return new Head(
1✔
41
                        isset($branchParts[2]) ? trim($branchParts[2]) : null,
1✔
42
                        is_readable($commitFile) && false !== ($commitHash = @file_get_contents($commitFile)) ? new CommitHash(trim($commitHash)) : null
1✔
43
                );
44
        }
45
}
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