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

AbstractHook   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 0
dl 0
loc 49
ccs 17
cts 17
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getContent() 0 8 2
A getRef() 0 6 1
A getProjectName() 0 10 1
getUrl() 0 1 ?
getBuildStatus() 0 1 ?
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