GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( dd13da...b61209 )
by Richard
04:01 queued 54s
created

Song::getSourceId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: wechsler
5
 * Date: 25/02/2017
6
 * Time: 18:30
7
 */
8
9
namespace Phase\TakeATicket\Model;
10
11
use Phase\TakeATicket\DataSource\AbstractSql;
12
13
class Song
14
{
15
    /**
16
     * @var int
17
     */
18
    protected $id;
19
20
    /**
21
     * @var string
22
     */
23
    protected $artist;
24
25
    /**
26
     * @var string
27
     */
28
    protected $title;
29
30
    /**
31
     * @var int
32
     */
33
    protected $sourceId;
34
35
    /**
36
     * Seconds
37
     *
38
     * @var int
39
     */
40
    protected $duration;
41
42
    /**
43
     * @var string
44
     */
45
    protected $codeNumber;
46
47
    /**
48
     * @return int
49
     */
50
    public function getId()
51
    {
52
        return $this->id;
53
    }
54
55
    /**
56
     * @param int $id
57
     * @return Song
58
     */
59
    public function setId($id)
60
    {
61
        $this->id = $id;
62
        return $this;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getArtist()
69
    {
70
        return $this->artist;
71
    }
72
73
    /**
74
     * @param string $artist
75
     * @return Song
76
     */
77
    public function setArtist($artist)
78
    {
79
        $this->artist = $artist;
80
        $this->updateLookupCode();
81
        return $this;
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getTitle()
88
    {
89
        return $this->title;
90
    }
91
92
    /**
93
     * @param string $title
94
     * @return Song
95
     */
96
    public function setTitle($title)
97
    {
98
        $this->title = $title;
99
        $this->updateLookupCode();
100
        return $this;
101
    }
102
103
    /**
104
     * @return int
105
     */
106
    public function getSourceId()
107
    {
108
        return $this->sourceId;
109
    }
110
111
    /**
112
     * @param int $sourceId
113
     * @return Song
114
     */
115
    public function setSourceId($sourceId)
116
    {
117
        $this->sourceId = $sourceId;
118
        return $this;
119
    }
120
121
    /**
122
     * @return int
123
     */
124
    public function getDuration()
125
    {
126
        return $this->duration;
127
    }
128
129
    /**
130
     * @param int $duration
131
     * @return Song
132
     */
133
    public function setDuration($duration)
134
    {
135
        $this->duration = $duration;
136
        return $this;
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public function getCodeNumber()
143
    {
144
        return $this->codeNumber;
145
    }
146
147
    /**
148
     * @param string $codeNumber
149
     * @return Song
150
     */
151
    protected function setCodeNumber($codeNumber)
152
    {
153
        $this->codeNumber = $codeNumber;
154
        return $this;
155
    }
156
157
    protected function updateLookupCode()
158
    {
159
        $codeNumber = null;
160
        if ($this->artist && $this->title) {
161
            $codeNumber = $this->generateLookupCode($this->artist, $this->title);
162
        }
163
        $this->setCodeNumber($codeNumber);
164
    }
165
166
    protected function generateLookupCode($artist, $title)
167
    {
168
        $normalisedSong = strtoupper(
169
            preg_replace('/[^a-z0-9]/i', '', $artist) .
170
            '::' .
171
            preg_replace('/[^a-z0-9]/i', '', $title)
172
        );
173
        $hash = (string)md5($normalisedSong);
174
        return strtoupper(substr($hash, 0, AbstractSql::CODE_LENGTH));
175
    }
176
}
177