ReleaseAnalyser   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 13
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B isSameBranch() 0 19 7
A __construct() 0 3 1
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs\Analysers;
7
8
class ReleaseAnalyser
9
{
10
    /**
11
     * @var \Vaimo\ComposerChangelogs\Resolvers\ReleaseDetailsResolver
12
     */
13
    private $detailsResolver;
14
15
    /**
16
     * @var string[]
17
     */
18
    private $mainBranches = array('main', 'master', 'default');
19
20
    public function __construct()
21
    {
22
        $this->detailsResolver = new \Vaimo\ComposerChangelogs\Resolvers\ReleaseDetailsResolver();
23
    }
24
25
    public function isSameBranch(array $item, $branch)
26
    {
27
        $branch = urldecode($branch);
28
29
        $itemBranch = $this->detailsResolver->resolveBranch($item);
30
31
        if (!$itemBranch && !$branch) {
32
            return true;
33
        }
34
        
35
        if (!$itemBranch && in_array($branch, $this->mainBranches, true)) {
36
            return true;
37
        }
38
39
        if ($itemBranch === $branch && isset($item['branch'])) {
40
            return true;
41
        }
42
43
        return false;
44
    }
45
}
46