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

GithubCommitId::createFromValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace DevBoardLib\GithubCore\Commit;
4
5
use DevBoardLib\GithubCore\Identifier;
6
use DevBoardLib\GithubCore\Repo\GithubRepoId;
7
8
/**
9
 * Class GithubCommitId.
10
 */
11 View Code Duplication
class GithubCommitId 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 GithubCommitSha */
16
    private $commitSha;
17
18
    /**
19
     * BranchId constructor.
20
     *
21
     * @param GithubRepoId    $githubRepoId
22
     * @param GithubCommitSha $commitSha
23
     */
24
    public function __construct(GithubRepoId $githubRepoId, GithubCommitSha $commitSha)
25
    {
26
        $this->githubRepoId = $githubRepoId;
27
        $this->commitSha    = $commitSha;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function __toString()
34
    {
35
        return $this->githubRepoId->__toString().'-'.$this->commitSha->__toString();
36
    }
37
38
    /**
39
     * @param $value
40
     *
41
     * @return GithubCommitId
42
     */
43
    public static function createFromValue($value)
44
    {
45
        list($repoId, $commitSha) = explode('-', $value, 2);
46
47
        return new self(new GithubRepoId($repoId), new GithubCommitSha($commitSha));
48
    }
49
}
50