Completed
Push — master ( 2cf029...6368d5 )
by Joachim
12:58
created

ShippingMethod::setFee()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Loevgaard\DandomainFoundation\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Loevgaard\DandomainFoundation;
7
use Loevgaard\DandomainFoundation\Entity\Generated\ShippingMethodInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...ShippingMethodInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Loevgaard\DandomainFoundation\Entity\Generated\ShippingMethodTrait;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...ted\ShippingMethodTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Money\Currency;
10
use Money\Money;
11
12
/**
13
 * @ORM\Entity()
14
 * @ORM\Table(name="ldf_shipping_methods")
15
 */
16
class ShippingMethod extends AbstractEntity implements ShippingMethodInterface
17
{
18
    use ShippingMethodTrait;
19
20
    /**
21
     * @var int
22
     *
23
     * @ORM\Id
24
     * @ORM\GeneratedValue
25
     * @ORM\Column(type="integer")
26
     **/
27
    protected $id;
28
29
    /**
30
     * @var int
31
     *
32
     * @ORM\Column(type="integer", unique=true)
33
     */
34
    protected $externalId;
35
36
    /**
37
     * @var string|null
38
     *
39
     * @ORM\Column(nullable=true, type="string", length=3)
40
     */
41
    protected $feeCurrency;
42
43
    /**
44
     * @var integer|null
45
     *
46
     * @ORM\Column(nullable=true, type="integer")
47
     */
48
    protected $feeAmount;
49
50
    /**
51
     * @var bool|null
52
     *
53
     * @ORM\Column(nullable=true, type="boolean")
54
     */
55
    protected $feeInclVat;
56
57
    /**
58
     * @var string|null
59
     *
60
     * @ORM\Column(nullable=true, type="string")
61
     */
62
    protected $name;
63
64
    /**
65
     * @return int
66
     */
67
    public function getId(): int
68
    {
69
        return (int)$this->id;
70
    }
71
72
    /**
73
     * @param int $id
74
     * @return ShippingMethod
75
     */
76
    public function setId($id)
77
    {
78
        $this->id = $id;
79
        return $this;
80
    }
81
82
    /**
83
     * @return int
84
     */
85
    public function getExternalId(): int
86
    {
87
        return (int)$this->externalId;
88
    }
89
90
    /**
91
     * @param int $externalId
92
     * @return ShippingMethod
93
     */
94
    public function setExternalId($externalId)
95
    {
96
        $this->externalId = $externalId;
97
        return $this;
98
    }
99
100
    /**
101
     * @return Money|null
102
     */
103
    public function getFee() : ?Money
104
    {
105
        if (!$this->feeCurrency) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->feeCurrency of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
106
            return null;
107
        }
108
109
        return new Money($this->feeAmount, new Currency($this->feeCurrency));
110
    }
111
112
    /**
113
     * @param Money $money
114
     * @return ShippingMethodInterface
115
     */
116
    public function setFee(Money $money) : ShippingMethodInterface
117
    {
118
        $this->feeAmount = $money->getAmount();
0 ignored issues
show
Documentation Bug introduced by
It seems like $money->getAmount() of type string is incompatible with the declared type null|integer of property $feeAmount.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
119
        $this->feeCurrency = $money->getCurrency()->getCode();
120
121
        return $this;
122
    }
123
124
    /**
125
     * @return bool|null
126
     */
127
    public function getFeeInclVat()
128
    {
129
        return $this->feeInclVat;
130
    }
131
132
    /**
133
     * @param bool|null $feeInclVat
134
     * @return ShippingMethodInterface
135
     */
136
    public function setFeeInclVat($feeInclVat)
137
    {
138
        $this->feeInclVat = $feeInclVat;
139
        return $this;
140
    }
141
142
    /**
143
     * @return null|string
144
     */
145
    public function getName()
146
    {
147
        return $this->name;
148
    }
149
150
    /**
151
     * @param null|string $name
152
     * @return ShippingMethodInterface
153
     */
154
    public function setName($name)
155
    {
156
        $this->name = $name;
157
        return $this;
158
    }
159
}
160