Passed
Push — master ( f4c77f...3f5b4e )
by Romain
36s
created

Referral::setRef()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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