Passed
Push — master ( 5ef314...276992 )
by Adrien
06:42
created

Account::setIban()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Traits\HasName;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
use Doctrine\ORM\Mapping as ORM;
11
use GraphQL\Doctrine\Annotation as API;
12
13
/**
14
 * A transaction account held for a member, or club's bank account
15
 *
16
 * @ORM\Entity(repositoryClass="Application\Repository\AccountRepository")
17
 * @ORM\AssociationOverrides({
18
 *     @ORM\AssociationOverride(name="owner", inversedBy="accounts",
19
 *         joinColumns=@ORM\JoinColumn(unique=true)
20
 *     )
21
 * })
22
 */
23
class Account extends AbstractModel
24
{
25
    use HasName;
26
27
    /**
28
     * @var string
29
     *
30
     * @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"})
31
     */
32
    private $balance = '0.00';
33
34
    /**
35
     * @var string
36
     *
37
     * @ORM\Column(type="string", length=32, unique=true)
38
     */
39
    private $iban;
40
41
    /**
42
     * @var Collection
43
     * @ORM\OneToMany(targetEntity="Transaction", mappedBy="account")
44
     */
45
    private $transactions;
46
47 5
    public function __construct()
48
    {
49 5
        $this->transactions = new ArrayCollection();
50 5
    }
51
52
    /**
53
     * Assign the transaction account to a user
54
     *
55
     * @param null|User $owner
56
     */
57 1
    public function setOwner(User $owner = null): void
58
    {
59 1
        if ($this->getOwner()) {
60 1
            $this->getOwner()->accountRemoved();
61
        }
62
63 1
        parent::setOwner($owner);
64
65 1
        if ($this->getOwner()) {
66 1
            $owner->accountAdded($this);
0 ignored issues
show
Bug introduced by
The method accountAdded() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
            $owner->/** @scrutinizer ignore-call */ 
67
                    accountAdded($this);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
        }
68 1
    }
69
70
    /**
71
     * Set balance
72
     *
73
     * @param string $balance
74
     *
75
     * @API\Exclude
76
     */
77
    public function setBalance(string $balance): void
78
    {
79
        $this->balance = $balance;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getBalance(): string
86
    {
87
        return $this->balance;
88
    }
89
90
    /**
91
     * Set the IBAN (international bank account number)
92
     *
93
     * @param string $iban
94
     */
95
    public function setIban(string $iban): void
96
    {
97
        $this->iban = $iban;
98
    }
99
100
    /**
101
     * Get the IBAN (international bank account number)
102
     *
103
     * @return string
104
     */
105
    public function getIban(): string
106
    {
107
        return $this->iban;
108
    }
109
110
    /**
111
     * Get all transactions
112
     *
113
     * @return Collection
114
     */
115 1
    public function getTransactions(): Collection
116
    {
117 1
        return $this->transactions;
118
    }
119
120
    /**
121
     * Notify the account that it has a new transaction
122
     * This should only be called by Transaction::setAccount()
123
     *
124
     * @param Transaction $transaction
125
     */
126 1
    public function transactionAdded(Transaction $transaction): void
127
    {
128 1
        $this->transactions->add($transaction);
129 1
    }
130
131
    /**
132
     * Notify the account that a transaction was removed
133
     * This should only be called by Transaction::setAccount()
134
     *
135
     * @param Transaction $transaction
136
     */
137 1
    public function transactionRemoved(Transaction $transaction): void
138
    {
139 1
        $this->transactions->removeElement($transaction);
140 1
    }
141
142
    /**
143
     * Notify that an user was added
144
     *
145
     * @param null|User $user
146
     */
147
    public function userAdded(?User $user): void
148
    {
149
        $this->user = $user;
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
150
    }
151
}
152