Completed
Push — master ( d19d30...257f70 )
by Joachim
13:38
created

PaymentMethod::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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\Entity\Generated\PaymentMethodInterface;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...\PaymentMethodInterface 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...
7
use Loevgaard\DandomainFoundation\Entity\Generated\PaymentMethodTrait;
0 ignored issues
show
Bug introduced by
The type Loevgaard\DandomainFound...ated\PaymentMethodTrait 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 Money\Currency;
9
use Money\Money;
10
11
/**
12
 * @ORM\Entity()
13
 * @ORM\Table(name="ldf_payment_methods")
14
 */
15
class PaymentMethod extends AbstractEntity implements PaymentMethodInterface
16
{
17
    use PaymentMethodTrait;
18
19
    /**
20
     * @var int
21
     *
22
     * @ORM\Id
23
     * @ORM\GeneratedValue
24
     * @ORM\Column(type="integer")
25
     **/
26
    protected $id;
27
28
    /**
29
     * @var int
30
     *
31
     * @ORM\Column(type="integer", unique=true)
32
     */
33
    protected $externalId;
34
35
    /**
36
     * @var string|null
37
     *
38
     * @ORM\Column(nullable=true, type="string", length=3)
39
     */
40
    protected $feeCurrency;
41
42
    /**
43
     * @var integer|null
44
     *
45
     * @ORM\Column(nullable=true, type="integer")
46
     */
47
    protected $feeAmount;
48
49
    /**
50
     * @var bool|null
51
     *
52
     * @ORM\Column(nullable=true, type="boolean")
53
     */
54
    protected $feeInclVat;
55
56
    /**
57
     * @var string|null
58
     *
59
     * @ORM\Column(nullable=true, type="string", length=191)
60
     */
61
    protected $name;
62
63
    public function __toString()
64
    {
65
        return (string)$this->name;
66
    }
67
68
    /**
69
     * @return int
70
     */
71
    public function getId(): int
72
    {
73
        return (int)$this->id;
74
    }
75
76
    /**
77
     * @param int $id
78
     * @return PaymentMethodInterface
79
     */
80
    public function setId($id)
81
    {
82
        $this->id = $id;
83
        return $this;
84
    }
85
86
    /**
87
     * @return int
88
     */
89
    public function getExternalId(): int
90
    {
91
        return (int)$this->externalId;
92
    }
93
94
    /**
95
     * @param int $externalId
96
     * @return PaymentMethodInterface
97
     */
98
    public function setExternalId($externalId)
99
    {
100
        $this->externalId = $externalId;
101
        return $this;
102
    }
103
104
    /**
105
     * @return Money|null
106
     */
107
    public function getFee() : ?Money
108
    {
109
        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...
110
            return null;
111
        }
112
113
        return new Money($this->feeAmount, new Currency($this->feeCurrency));
114
    }
115
116
    /**
117
     * @param Money $money
118
     * @return PaymentMethodInterface
119
     */
120
    public function setFee(Money $money) : PaymentMethodInterface
121
    {
122
        $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...
123
        $this->feeCurrency = $money->getCurrency()->getCode();
124
125
        return $this;
126
    }
127
128
    /**
129
     * @return bool|null
130
     */
131
    public function getFeeInclVat()
132
    {
133
        return $this->feeInclVat;
134
    }
135
136
    /**
137
     * @param bool|null $feeInclVat
138
     * @return PaymentMethodInterface
139
     */
140
    public function setFeeInclVat($feeInclVat)
141
    {
142
        $this->feeInclVat = $feeInclVat;
143
        return $this;
144
    }
145
146
    /**
147
     * @return null|string
148
     */
149
    public function getName()
150
    {
151
        return $this->name;
152
    }
153
154
    /**
155
     * @param null|string $name
156
     * @return PaymentMethodInterface
157
     */
158
    public function setName($name)
159
    {
160
        $this->name = $name;
161
        return $this;
162
    }
163
}
164