Passed
Push — master ( d8a10a...d39919 )
by Allan
02:25
created

ChangelogReleaseResolver::matchBranch()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 17
c 0
b 0
f 0
rs 8.4444
cc 8
nc 4
nop 2
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs\Resolvers;
7
8
class ChangelogReleaseResolver
9
{
10
    /**
11
     * @var \Vaimo\ComposerChangelogs\Validators\ConstraintValidator
12
     */
13
    private $constraintValidator;
14
15
    /**
16
     * @var \Vaimo\ComposerChangelogs\Analysers\ReleaseAnalyser
17
     */
18
    private $releaseAnalyser;
19
20
    public function __construct()
21
    {
22
        $this->constraintValidator = new \Vaimo\ComposerChangelogs\Validators\ConstraintValidator();
23
        $this->releaseAnalyser = new \Vaimo\ComposerChangelogs\Analysers\ReleaseAnalyser();
24
    }
25
26
    public function resolveLatestVersionedRelease(array $changelog, $branch = '')
27
    {
28
        foreach ($changelog as $version => $item) {
29
            if (!$this->constraintValidator->isConstraint($version)) {
30
                continue;
31
            }
32
33
            if (!$this->releaseAnalyser->isSameBranch($item, $branch)) {
34
                continue;
35
            }
36
37
            return $version;
38
        }
39
40
        return false;
41
    }
42
43
    public function resolveUpcomingRelease(array $changelog, $branch = '')
44
    {
45
        foreach ($changelog as $version => $item) {
46
            if ($this->constraintValidator->isConstraint($version)) {
47
                break;
48
            }
49
50
            if (!$this->releaseAnalyser->isSameBranch($item, $branch)) {
51
                continue;
52
            }
53
54
            return $version;
55
        }
56
57
        return false;
58
    }
59
}
60