UrlTrait::setUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/qrcode-library project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\QrCode\Traits;
13
14
use Da\QrCode\Exception\InvalidConfigException;
15
16
trait UrlTrait
17
{
18
    /**
19
     * @var string a valid URL
20
     */
21
    protected $url;
22
23
    /**
24
     * @param string $value the URL
25
     *
26
     * @throws InvalidConfigException
27
     */
28
    public function setUrl(string $value)
29
    {
30
        $error = null;
0 ignored issues
show
Unused Code introduced by
$error is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
31
32
        if (!filter_var($value, FILTER_VALIDATE_URL)) {
33
            throw new InvalidConfigException('Url seems invalid.');
34
        }
35
36
        $this->url = $value;
37
    }
38
39
    /**
40
     * @return string the URL
41
     */
42
    public function getUrl()
43
    {
44
        return $this->url;
45
    }
46
}
47