Completed
Push — master ( 3cec9f...194832 )
by Miro
05:20 queued 02:28
created

GithubBranchId::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 5
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace DevBoardLib\GithubCore\Branch;
4
5
use DevBoardLib\GithubCore\Identifier;
6
use DevBoardLib\GithubCore\Repo\GithubRepoId;
7
8
/**
9
 * Class GithubBranchId.
10
 */
11 View Code Duplication
class GithubBranchId implements Identifier
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /** @var GithubRepoId */
14
    private $githubRepoId;
15
    /** @var string */
16
    private $branchName;
17
18
    /**
19
     * BranchId constructor.
20
     *
21
     * @param GithubRepoId $githubRepoId
22
     * @param              $branchName
23
     */
24
    public function __construct(GithubRepoId $githubRepoId, $branchName)
25
    {
26
        $this->githubRepoId = $githubRepoId;
27
        $this->branchName   = $branchName;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function __toString()
34
    {
35
        return $this->githubRepoId->__toString().'-'.$this->branchName;
36
    }
37
38
    /**
39
     * @param $value
40
     *
41
     * @return GithubBranchId
42
     */
43
    public static function createFromValue($value)
44
    {
45
        list($repoId, $branchName) = explode('-', $value, 2);
46
47
        return new self(new GithubRepoId($repoId), $branchName);
48
    }
49
}
50