Passed
Push — master ( 73f61b...6db8b4 )
by David
51s
created

AbstractReceiver::setApi()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace FlexyProject\GitHub\Receiver;
3
4
use FlexyProject\GitHub\AbstractApi;
5
6
/**
7
 * Class AbstractReceiver
8
 *
9
 * @package FlexyProject\GitHub\Receiver
10
 */
11
abstract class AbstractReceiver
12
{
13
    /** Api trait */
14
    use Api;
15
16
    /** Protected properties */
17
    protected $owner = '';
18
    protected $repo  = '';
19
20
    /**
21
     * Constructor
22
     *
23
     * @param AbstractApi $api
24
     */
25
    public function __construct(AbstractApi $api)
26
    {
27
        $this->setApi($api);
28
    }
29
30
    /**
31
     * Get owner
32
     *
33
     * @return string
34
     */
35
    public function getOwner(): string
36
    {
37
        return $this->owner;
38
    }
39
40
    /**
41
     * Set owner
42
     *
43
     * @param string $owner
44
     *
45
     * @return AbstractReceiver
46
     */
47
    public function setOwner(string $owner): AbstractReceiver
48
    {
49
        $this->owner = $owner;
50
51
        return $this;
52
    }
53
54
    /**
55
     * Get repository
56
     *
57
     * @return string
58
     */
59
    public function getRepo(): string
60
    {
61
        return $this->repo;
62
    }
63
64
    /**
65
     * Set repository
66
     *
67
     * @param string $repo
68
     *
69
     * @return AbstractReceiver
70
     */
71
    public function setRepo(string $repo): AbstractReceiver
72
    {
73
        $this->repo = $repo;
74
75
        return $this;
76
    }
77
78
    /**
79
     * Get a sub-receiver
80
     *
81
     * @param string $name
82
     *
83
     * @return null|object
84
     */
85
    public function getReceiver(string $name)
86
    {
87
        $classPath = explode('\\', get_called_class());
88
        $class     = (string)$this->getApi()
89
                                  ->sprintf(':namespace\:class\:method', __NAMESPACE__, end($classPath), $name);
90
91
        if (class_exists($class)) {
92
            return new $class($this);
93
        }
94
95
        return null;
96
    }
97
}