Completed
Push — master ( da2f6e...d3b8cb )
by Kamil
20:06
created

SitemapUrl::setPriority()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.2
cc 4
eloc 5
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Sylius\Bundle\CoreBundle\Sitemap\Model;
13
14
/**
15
 * @author Arkadiusz Krakowiak <[email protected]>
16
 */
17
class SitemapUrl implements SitemapUrlInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    private $localization;
23
24
    /**
25
     * @var \DateTime
26
     */
27
    private $lastModification;
28
29
    /**
30
     * @var ChangeFrequency
31
     */
32
    private $changeFrequency;
33
34
    /**
35
     * @var float
36
     */
37
    private $priority;
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getLocalization()
43
    {
44
        return $this->localization;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function setLocalization($localization)
51
    {
52
        $this->localization = $localization;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getLastModification()
59
    {
60
        return $this->lastModification;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function setLastModification(\DateTime $lastModification)
67
    {
68
        $this->lastModification = $lastModification;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getChangeFrequency()
75
    {
76
        return (string) $this->changeFrequency;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function setChangeFrequency(ChangeFrequency $changeFrequency)
83
    {
84
        $this->changeFrequency = $changeFrequency;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getPriority()
91
    {
92
        return $this->priority;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function setPriority($priority)
99
    {
100
        if (!is_numeric($priority) || 0 >= $priority || 1 <= $priority) {
101
            throw new \InvalidArgumentException(sprintf(
102
                'The value %s is not supported by the option priority, it must be a numeric between 0.0 and 1.0.', $priority
103
            ));
104
        }
105
106
        $this->priority = $priority;
0 ignored issues
show
Documentation Bug introduced by
It seems like $priority can also be of type integer or string. However, the property $priority is declared as type double. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
107
    }
108
}
109