Tag   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCommits() 0 3 1
A doName() 0 10 2
A isAnnotated() 0 8 2
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Biurad opensource projects.
5
 *
6
 * @copyright 2022 Biurad Group (https://biurad.com/)
7
 * @license   https://opensource.org/licenses/BSD-3-Clause License
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Biurad\Git;
14
15
use Symfony\Component\Process\Exception\ExceptionInterface;
16
17
/**
18
 * Represents a git tag object.
19
 *
20
 * @author Divine Niiquaye Ibok <[email protected]>
21
 */
22
class Tag extends Revision
23
{
24
    public function isAnnotated(): bool
25
    {
26
        try {
27
            $tag = $this->repository->run('cat-file', ['tag', $this->revision]);
28
        } catch (ExceptionInterface) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
29
        }
30
31
        return null !== ($tag ?? null);
32
    }
33
34
    /**
35
     * @param null|int $offset Start listing from a given position
36
     * @param null|int $limit  Limit the fetched number of commits
37
     *
38
     * @return array<int,Commit>
39
     */
40
    public function getCommits(int $offset = null, int $limit = null): array
41
    {
42
        return $this->repository->getLog($this->getName(), null, $offset, $limit)->getCommits();
43
    }
44
45
    protected function doName(): string
46
    {
47
        if (\str_starts_with($ref = $this->revision, 'refs/tags/')) {
48
            return \substr($this->revision, 10);
49
        }
50
51
        // Maybe we should throw an exception here? I'm not sure.
52
        $this->revision = 'refs/tags/'.$this->revision;
53
54
        return $ref;
55
    }
56
}
57