Passed
Pull Request — master (#48)
by Romain
02:32
created

Referral::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Kerox\Messenger\Model;
4
5
class Referral
6
{
7
8
    /**
9
     * @var string
10
     */
11
    protected $source;
12
13
    /**
14
     * @var string
15
     */
16
    protected $type;
17
18
    /**
19
     * @var string
20
     */
21
    protected $adId;
22
23
    /**
24
     * @var null|string
25
     */
26
    protected $ref;
27
28
    /**
29
     * Referral constructor.
30
     *
31
     * @param string $source
32
     * @param string $type
33
     * @param string $adId
34
     */
35 2
    public function __construct(string $source, string $type, string $adId)
36
    {
37 2
        $this->source = $source;
38 2
        $this->type = $type;
39 2
        $this->adId = $adId;
40 2
    }
41
42
    /**
43
     * @return string
44
     */
45 1
    public function getSource(): string
46
    {
47 1
        return $this->source;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 1
    public function getType(): string
54
    {
55 1
        return $this->type;
56
    }
57
58
    /**
59
     * @return string
60
     */
61 1
    public function getAdId(): string
62
    {
63 1
        return $this->adId;
64
    }
65
66
    /**
67
     * @return null|string
68
     */
69 1
    public function getRef()
70
    {
71 1
        return $this->ref;
72
    }
73
74
    /**
75
     * @param string $ref
76
     * @return \Kerox\Messenger\Model\Referral
77
     */
78 2
    public function setRef(string $ref): Referral
79
    {
80 2
        $this->ref = $ref;
81
82 2
        return $this;
83
    }
84
85
    /**
86
     * @param array $referral
87
     * @return \Kerox\Messenger\Model\Referral
88
     */
89 2
    public static function create(array $referral): Referral
90
    {
91 2
        $self = new static($referral['source'], $referral['type'], $referral['ad_id']);
92 2
        if (isset($referral['ref'])) {
93 2
            $self->setRef($referral['ref']);
94
        }
95
96 2
        return $self;
97
    }
98
}
99