Completed
Push — master ( 53cfc7...49d128 )
by Rémi
07:38
created

AbstractHook::getContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php namespace G2R\Gitlab\Hook;
2
3
abstract class AbstractHook
4
{
5
    protected $hookContent;
6
7
    protected $buildStatus;
8
9 24
    public function __construct($hookContent)
10
    {
11 24
        $this->hookContent = $hookContent;
12 24
    }
13
14 16
    public function getContent()
15
    {
16 16
        if (gettype($this->hookContent) == 'string') {
17 16
            $this->hookContent = json_decode($this->hookContent);
18 8
        }
19
20 16
        return $this->hookContent;
21
    }
22
23 6
    public function getRef()
24
    {
25 6
        $ref = explode('/', $this->getContent()->ref);
26
27 6
        return array_pop($ref);
28
    }
29
30 6
    public function getProjectName()
31
    {
32 6
        preg_match(
33 6
            '/.*\/(.+\/.+)/',
34 6
            $this->getUrl(),
35
            $matches
36 3
        );
37
38 6
        return preg_replace('/\.git$/', '', array_pop($matches));
39
    }
40
41
    /**
42
     * Return the project url
43
     * @return string
44
     */
45
    abstract public function getUrl();
46
47
    /**
48
     * Return the Build status (success, failed, running)
49
     */
50
    abstract public function getBuildStatus();
51
}
52