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.

QRCode::fullName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @title            QR Code
4
 * @desc             Compatible to vCard 4.0 or higher.
5
 *
6
 * @author           Pierre-Henry Soria <[email protected]>
7
 * @copyright        (c) 2012-2018, Pierre-Henry Soria. All Rights Reserved.
8
 * @license          GNU General Public License <http://www.gnu.org/licenses/gpl.html>
9
 * @version          1.2
10
 */
11
12
class QRCode
13
{
14
    const API_URL = 'https://chart.googleapis.com/chart?chs=';
15
16
    private $sData;
17
18
    /**
19
     * Constructor.
20
     */
21
    public function __construct()
22
    {
23
        $this->sData = 'BEGIN:VCARD' . "\n";
24
        $this->sData .= 'VERSION:4.0' . "\n";
25
    }
26
27
    /**
28
     * The name of the person.
29
     *
30
     * @param string $sName
31
     *
32
     * @return self
33
     */
34
    public function name($sName)
35
    {
36
        $this->sData .= 'N:' . $sName . "\n";
37
        return $this;
38
    }
39
40
    /**
41
     * The full name of the person.
42
     *
43
     * @param string $sFullName
44
     *
45
     * @return self this
46
     */
47
    public function fullName($sFullName)
48
    {
49
        $this->sData .= 'FN:' . $sFullName . "\n";
50
        return $this;
51
    }
52
53
    /**
54
     * @param string $sAddress
55
     *
56
     * @return self
57
     */
58
    public function address($sAddress)
59
    {
60
        $this->sData .= 'ADR:' . $sAddress . "\n";
61
62
        return $this;
63
    }
64
65
    /**
66
     * @param string $sNickname
67
     *
68
     * @return self
69
     */
70
    public function nickName($sNickname)
71
    {
72
        $this->sData .= 'NICKNAME:' . $sNickname . "\n";
73
        return $this;
74
    }
75
76
    /**
77
     * @param string $sMail
78
     *
79
     * @return self
80
     */
81
    public function email($sMail)
82
    {
83
        $this->sData .= 'EMAIL;TYPE=PREF,INTERNET:' . $sMail . "\n";
84
        return $this;
85
    }
86
87
    /**
88
     * @param string $sVal
89
     *
90
     * @return self
91
     */
92
    public function workPhone($sVal)
93
    {
94
        $this->sData .= 'TEL;TYPE=WORK:' . $sVal . "\n";
95
        return $this;
96
    }
97
98
    /**
99
     * @param string $sVal
100
     *
101
     * @return self
102
     */
103
    public function homePhone($sVal)
104
    {
105
        $this->sData .= 'TEL;TYPE=HOME:' . $sVal . "\n";
106
        return $this;
107
    }
108
109
    /**
110
     * @param string $sUrl
111
     *
112
     * @return self
113
     */
114
    public function url($sUrl)
115
    {
116
        $sUrl = (substr($sUrl, 0, 4) != 'http') ? 'http://' . $sUrl : $sUrl;
117
        $this->sData .= 'URL:' . $sUrl . "\n";
118
        return $this;
119
    }
120
121
    /**
122
     * @param string $sPhone
123
     * @param string $sText
124
     *
125
     * @return self
126
     */
127
    public function sms($sPhone, $sText)
128
    {
129
        $this->sData .= 'SMSTO:' . $sPhone . ':' . $sText . "\n";
130
        return $this;
131
    }
132
133
    /**
134
     * @param string $sBirthday Date in the format YYYY-MM-DD or ISO 8601
135
     *
136
     * @return self
137
     */
138
    public function birthday($sBirthday)
139
    {
140
        $this->sData .= 'BDAY:' . $sBirthday . "\n";
141
        return $this;
142
    }
143
144
    /**
145
     * @param string $sBirthDate Date in the format YYYY-MM-DD or ISO 8601
146
     *
147
     * @return self
148
     */
149
    public function anniversary($sBirthDate)
150
    {
151
        $this->sData .= 'ANNIVERSARY:' . $sBirthDate . "\n";
152
        return $this;
153
    }
154
155
    /**
156
     * @param string $sSex F = Female. M = Male
157
     *
158
     * @return self
159
     */
160
    public function gender($sSex)
161
    {
162
        $this->sData .= 'GENDER:' . $sSex . "\n";
163
        return $this;
164
    }
165
166
    /**
167
     * A list of "tags" that can be used to describe the object represented by this vCard.
168
     *
169
     * @param string $sCategories
170
     *
171
     * @return self
172
     */
173
    public function categories($sCategories)
174
    {
175
        $this->sData .= 'CATEGORIES:' . $sCategories . "\n";
176
        return $this;
177
    }
178
179
    /**
180
     * The instant messenger (Instant Messaging and Presence Protocol).
181
     *
182
     * @param string $sVal
183
     *
184
     * @return self
185
     */
186
    public function impp($sVal)
187
    {
188
        $this->sData .= 'IMPP:' . $sVal . "\n";
189
        return $this;
190
    }
191
192
    /**
193
     * Photo (avatar).
194
     *
195
     * @param string $sImgUrl URL of the image.
196
     *
197
     * @return self
198
     *
199
     * @throws InvalidArgumentException If the image format is invalid.
200
     */
201
    public function photo($sImgUrl)
202
    {
203
        $bIsImgExt = strtolower(substr(strrchr($sImgUrl, '.'), 1)); // Get the file extension.
204
205
        if ($bIsImgExt == 'jpeg' || $bIsImgExt == 'jpg' || $bIsImgExt == 'png' || $bIsImgExt == 'gif') {
206
            $sExt = strtoupper($bIsImgExt);
207
        } else {
208
            throw new InvalidArgumentException('Invalid format Image!');
209
        }
210
211
        $this->sData .= 'PHOTO;VALUE=URL;TYPE=' . $sExt . ':' . $sImgUrl . "\n";
212
213
        return $this;
214
    }
215
216
    /**
217
     * The role, occupation, or business category of the vCard object within an organization.
218
     *
219
     * @param string $sRole e.g., Executive
220
     *
221
     * @return self
222
     */
223
    public function role($sRole)
224
    {
225
        $this->sData .= 'ROLE:' . $sRole . "\n";
226
        return $this;
227
    }
228
229
    /**
230
     * The organization / company.
231
     *
232
     * The name and optionally the unit(s) of the organization
233
     * associated with the vCard object. This property is based on the X.520 Organization Name
234
     * attribute and the X.520 Organization Unit attribute.
235
     *
236
     * @param string $sOrg e.g., Google;GMail Team;Spam Detection Squad
237
     *
238
     * @return self
239
     */
240
    public function organization($sOrg)
241
    {
242
        $this->sData .= 'ORG:' . $sOrg . "\n";
243
        return $this;
244
    }
245
246
    /**
247
     * The supplemental information or a comment that is associated with the vCard.
248
     *
249
     * @param string $sText
250
     *
251
     * @return self
252
     */
253
    public function note($sText)
254
    {
255
        $this->sData .= 'NOTE:' . $sText . "\n";
256
        return $this;
257
    }
258
259
    /**
260
     * @param string $sTitle
261
     * @param string $sUrl
262
     *
263
     * @return self
264
     */
265
    public function bookmark($sTitle, $sUrl)
266
    {
267
        $this->sData .= 'MEBKM:TITLE:' . $sTitle . ';URL:' . $sUrl . "\n";
268
        return $this;
269
    }
270
271
    /**
272
     * Geo location.
273
     *
274
     * @param string $sLat Latitude
275
     * @param string $sLon Longitude
276
     * @param integer $iHeight Height
277
     *
278
     * @return self
279
     */
280
    public function geo($sLat, $sLon, $iHeight)
281
    {
282
        $this->sData .= 'GEO:' . $sLat . ',' . $sLon . ',' . $iHeight . "\n";
283
        return $this;
284
    }
285
286
    /**
287
     * The language that the person speaks.
288
     *
289
     * @param string $sLang e.g., en-US
290
     *
291
     * @return self
292
     */
293
    public function lang($sLang)
294
    {
295
        $this->sData .= 'LANG:' . $sLang . "\n";
296
        return $this;
297
    }
298
299
    /**
300
     * @param string $sType
301
     * @param string $sSsid
302
     * @param string $sPwd
303
     *
304
     * @return self
305
     */
306
    public function wifi($sType, $sSsid, $sPwd)
307
    {
308
        $this->sData .= 'WIFI:T:' . $sType . ';S' . $sSsid . ';' . $sPwd . "\n";
309
        return $this;
310
    }
311
312
    /**
313
     * Generate the QR code.
314
     *
315
     * @return self
316
     */
317
    public function finish()
318
    {
319
        $this->sData .= 'END:VCARD';
320
        $this->sData = urlencode($this->sData);
321
        return $this;
322
    }
323
324
    /**
325
     * Get the URL of QR Code.
326
     *
327
     * @param integer $iSize Default 150
328
     * @param string $sECLevel Default L
329
     * @param integer $iMargin Default 1
330
     *
331
     * @return string The API URL configure.
332
     */
333
    public function get($iSize = 150, $sECLevel = 'L', $iMargin = 1)
334
    {
335
        return self::API_URL . $iSize . 'x' . $iSize . '&cht=qr&chld=' . $sECLevel . '|' . $iMargin . '&chl=' . $this->sData;
336
    }
337
338
    /**
339
     * The HTML code for displaying the QR Code.
340
     *
341
     * @return void
342
     */
343
    public function display()
344
    {
345
        echo '<p class="center"><img src="' . $this->_cleanUrl($this->get()) . '" alt="QR Code" /></p>';
346
    }
347
348
    /**
349
     * Clean URL.
350
     *
351
     * @param string $sUrl
352
     *
353
     * @return string
354
     */
355
    private function _cleanUrl($sUrl)
356
    {
357
        return str_replace('&', '&amp;', $sUrl);
358
    }
359
}
360