Client   A
last analyzed

Complexity

Total Complexity 30

Size/Duplication

Total Lines 201
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 14

Importance

Changes 0
Metric Value
wmc 30
lcom 2
cbo 14
dl 0
loc 201
rs 10
c 0
b 0
f 0

26 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getPassword() 0 4 1
A getSalt() 0 4 1
A getUsername() 0 4 1
A eraseCredentials() 0 3 1
A getRoles() 0 6 1
A serialize() 0 4 1
A unserialize() 0 9 2
A isEqualTo() 0 16 4
A getOrders() 0 6 1
A getClientDetails() 0 4 1
A setClientDetails() 0 4 1
A getContactDetails() 0 4 1
A setContactDetails() 0 4 1
A getBillingAddress() 0 4 1
A setBillingAddress() 0 4 1
A getShippingAddress() 0 4 1
A setShippingAddress() 0 4 1
A getEncoderName() 0 4 1
A getClientGroup() 0 4 1
A setClientGroup() 0 4 1
A getMinimumOrderAmount() 0 4 1
A setMinimumOrderAmount() 0 4 1
A isAccountNonExpired() 0 4 1
A isAccountNonLocked() 0 4 1
A isCredentialsNonExpired() 0 4 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
namespace WellCommerce\Bundle\AppBundle\Entity;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Knp\DoctrineBehaviors\Model\Blameable\Blameable;
17
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable;
18
use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface;
19
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
20
use Symfony\Component\Security\Core\User\EquatableInterface;
21
use Symfony\Component\Security\Core\User\UserInterface;
22
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Enableable;
23
use WellCommerce\Bundle\CoreBundle\Doctrine\Behaviours\Identifiable;
24
use WellCommerce\Bundle\CoreBundle\Entity\EntityInterface;
25
use WellCommerce\Bundle\OrderBundle\Entity\Order;
26
use WellCommerce\Extra\AppBundle\Entity\ClientExtraTrait;
27
28
/**
29
 * Class Client
30
 *
31
 * @author  Adam Piotrowski <[email protected]>
32
 */
33
class Client implements EntityInterface, \Serializable, UserInterface, EquatableInterface, EncoderAwareInterface, AdvancedUserInterface
34
{
35
    const ROLE_CLIENT = 'ROLE_CLIENT';
36
    
37
    use Identifiable;
38
    use Enableable;
39
    use Timestampable;
40
    use Blameable;
41
    use ShopAwareTrait;
42
    use ClientExtraTrait;
43
    
44
    /**
45
     * @var Collection
46
     */
47
    protected $orders;
48
    
49
    /**
50
     * @var ClientDetails
51
     */
52
    protected $clientDetails;
53
    
54
    /**
55
     * @var ClientContactDetails
56
     */
57
    protected $contactDetails;
58
    
59
    /**
60
     * @var ClientBillingAddress
61
     */
62
    protected $billingAddress;
63
    
64
    /**
65
     * @var ClientShippingAddress
66
     */
67
    protected $shippingAddress;
68
    
69
    /**
70
     * @var ClientGroup
71
     */
72
    protected $clientGroup;
73
    
74
    /**
75
     * @var MinimumOrderAmount
76
     */
77
    protected $minimumOrderAmount;
78
    
79
    public function __construct()
80
    {
81
        $this->orders             = new ArrayCollection();
82
        $this->clientDetails      = new ClientDetails();
83
        $this->contactDetails     = new ClientContactDetails();
84
        $this->billingAddress     = new ClientBillingAddress();
85
        $this->shippingAddress    = new ClientShippingAddress();
86
        $this->minimumOrderAmount = new MinimumOrderAmount();
87
    }
88
    
89
    public function getPassword()
90
    {
91
        return $this->clientDetails->getPassword();
92
    }
93
    
94
    public function getSalt()
95
    {
96
        return null;
97
    }
98
    
99
    public function getUsername()
100
    {
101
        return $this->clientDetails->getUsername();
102
    }
103
    
104
    public function eraseCredentials()
105
    {
106
    }
107
    
108
    public function getRoles()
109
    {
110
        return [
111
            self::ROLE_CLIENT,
112
        ];
113
    }
114
    
115
    public function serialize()
116
    {
117
        return serialize([$this->id, $this->getUsername(), $this->getPassword(), $this->isEnabled()]);
118
    }
119
    
120
    public function unserialize($serialized)
121
    {
122
        list($this->id, $username, $password, $enabled) = unserialize($serialized);
0 ignored issues
show
Unused Code introduced by Adam Piotrowski
The assignment to $enabled is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
123
        if (!$this->clientDetails instanceof ClientDetails) {
124
            $this->clientDetails = new ClientDetails();
125
        }
126
        $this->clientDetails->setUsername($username);
127
        $this->clientDetails->setPassword($password);
128
    }
129
    
130
    public function isEqualTo(UserInterface $user)
131
    {
132
        if (!$user instanceof Client) {
133
            return false;
134
        }
135
        
136
        if ($this->getPassword() !== $user->getPassword()) {
137
            return false;
138
        }
139
        
140
        if ($this->getUsername() !== $user->getUsername()) {
141
            return false;
142
        }
143
        
144
        return true;
145
    }
146
    
147
    public function getOrders(): Collection
148
    {
149
        return $this->orders->filter(function (Order $order) {
150
            return $order->isConfirmed();
151
        });
152
    }
153
    
154
    public function getClientDetails(): ClientDetails
155
    {
156
        return $this->clientDetails;
157
    }
158
    
159
    public function setClientDetails(ClientDetails $clientDetails)
160
    {
161
        $this->clientDetails = $clientDetails;
162
    }
163
    
164
    public function getContactDetails(): ClientContactDetails
165
    {
166
        return $this->contactDetails;
167
    }
168
    
169
    public function setContactDetails(ClientContactDetails $contactDetails)
170
    {
171
        $this->contactDetails = $contactDetails;
172
    }
173
    
174
    public function getBillingAddress(): ClientBillingAddress
175
    {
176
        return $this->billingAddress;
177
    }
178
    
179
    public function setBillingAddress(ClientBillingAddress $billingAddress)
180
    {
181
        $this->billingAddress = $billingAddress;
182
    }
183
    
184
    public function getShippingAddress(): ClientShippingAddress
185
    {
186
        return $this->shippingAddress;
187
    }
188
    
189
    public function setShippingAddress(ClientShippingAddress $shippingAddress)
190
    {
191
        $this->shippingAddress = $shippingAddress;
192
    }
193
    
194
    public function getEncoderName()
195
    {
196
        return $this->clientDetails->getLegacyPasswordEncoder() ?? null;
197
    }
198
    
199
    public function getClientGroup()
200
    {
201
        return $this->clientGroup;
202
    }
203
    
204
    public function setClientGroup(ClientGroup $clientGroup = null)
205
    {
206
        $this->clientGroup = $clientGroup;
207
    }
208
    
209
    public function getMinimumOrderAmount(): MinimumOrderAmount
210
    {
211
        return $this->minimumOrderAmount;
212
    }
213
    
214
    public function setMinimumOrderAmount(MinimumOrderAmount $minimumOrderAmount)
215
    {
216
        $this->minimumOrderAmount = $minimumOrderAmount;
217
    }
218
219
    public function isAccountNonExpired()
220
    {
221
        return true;
222
    }
223
224
    public function isAccountNonLocked()
225
    {
226
        return true;
227
    }
228
229
    public function isCredentialsNonExpired()
230
    {
231
        return true;
232
    }
233
}
234