User::getAuthService()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace ZfcUser\Service;
4
5
use Zend\Authentication\AuthenticationServiceInterface as AuthenticationService;
6
use Zend\Form\FormInterface as Form;
7
use Zend\ServiceManager\ServiceManager;
8
use Zend\ServiceManager\ServiceManagerAwareInterface;
9
use ZfcBase\EventManager\EventProvider;
10
use ZfcUser\Mapper\HydratorInterface as Hydrator;
11
use ZfcUser\Mapper\UserInterface as UserMapper;
12
use ZfcUser\Options\UserServiceOptionsInterface as ServiceOptions;
13
14
class User extends EventProvider implements ServiceManagerAwareInterface
15
{
16
    /**
17
     * @var UserMapper
18
     */
19
    protected $userMapper;
20
21
    /**
22
     * @var AuthenticationService
23
     */
24
    protected $authService;
25
26
    /**
27
     * @var Form
28
     */
29
    protected $loginForm;
30
31
    /**
32
     * @var Form
33
     */
34
    protected $registerForm;
35
36
    /**
37
     * @var ServiceManager
38
     */
39
    protected $serviceManager;
40
41
    /**
42
     * @var ServiceOptions
43
     */
44
    protected $options;
45
46
    /**
47
     * @var Hydrator
48
     */
49
    protected $formHydrator;
50
51
    /**
52
     * createFromForm
53
     *
54
     * @param array $data
55
     * @return \ZfcUser\Entity\UserInterface
56
     * @throws Exception\InvalidArgumentException
57
     */
58
    public function register(array $data)
59
    {
60
        $entityClass = $this->getOptions()->getUserEntityClass();
61
        $form        = $this->getRegisterForm();
62
63
        $form->setHydrator($this->getFormHydrator());
64
        $form->bind(new $entityClass);
65
        $form->setData($data);
66
67
        if ($form->isValid()) {
68
            $user   = $form->getData();
0 ignored issues
show
Bug Compatibility introduced by
The expression $form->getData(); of type array|object adds the type array to the return on line 77 which is incompatible with the return type documented by ZfcUser\Service\User::register of type ZfcUser\Entity\UserInterface.
Loading history...
69
            $events = $this->getEventManager();
70
71
            $user->setPassword($this->getFormHydrator()->getCryptoService()->create($user->getPassword()));
72
73
            $events->trigger(__FUNCTION__, $this, compact('user', 'form'));
74
            $this->getUserMapper()->insert($user);
75
            $events->trigger(__FUNCTION__.'.post', $this, compact('user', 'form'));
76
77
            return $user;
78
        }
79
        return false;
80
    }
81
82
    /**
83
     * getUserMapper
84
     *
85
     * @return UserMapper
86
     */
87
    public function getUserMapper()
88
    {
89
        if (null === $this->userMapper) {
90
            $this->setUserMapper($this->serviceManager->get('zfcuser_user_mapper'));
0 ignored issues
show
Documentation introduced by
$this->serviceManager->get('zfcuser_user_mapper') is of type object|array, but the function expects a object<ZfcUser\Mapper\UserInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
91
        }
92
        return $this->userMapper;
93
    }
94
95
    /**
96
     * setUserMapper
97
     *
98
     * @param UserMapperInterface $userMapper
99
     * @return User
100
     */
101
    public function setUserMapper(UserMapper $userMapper)
102
    {
103
        $this->userMapper = $userMapper;
104
        return $this;
105
    }
106
107
    /**
108
     * getAuthService
109
     *
110
     * @return AuthenticationService
111
     */
112
    public function getAuthService()
113
    {
114
        if (null === $this->authService) {
115
            $this->setAuthService($this->serviceManager->get('zfcuser_auth_service'));
0 ignored issues
show
Documentation introduced by
$this->serviceManager->g...'zfcuser_auth_service') is of type object|array, but the function expects a object<Zend\Authenticati...cationServiceInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
        }
117
        return $this->authService;
118
    }
119
120
    /**
121
     * setAuthenticationService
122
     *
123
     * @param AuthenticationService $authService
124
     * @return User
125
     */
126
    public function setAuthService(AuthenticationService $authService)
127
    {
128
        $this->authService = $authService;
129
        return $this;
130
    }
131
132
    /**
133
     * @return Form
134
     */
135
    public function getRegisterForm()
136
    {
137
        if (null === $this->registerForm) {
138
            $this->setRegisterForm($this->serviceManager->get('zfcuser_register_form'));
0 ignored issues
show
Documentation introduced by
$this->serviceManager->g...zfcuser_register_form') is of type object|array, but the function expects a object<Zend\Form\FormInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
139
        }
140
        return $this->registerForm;
141
    }
142
143
    /**
144
     * @param Form $registerForm
145
     * @return User
146
     */
147
    public function setRegisterForm(Form $registerForm)
148
    {
149
        $this->registerForm = $registerForm;
150
        return $this;
151
    }
152
153
    /**
154
     * get service options
155
     *
156
     * @return UserServiceOptionsInterface
157
     */
158
    public function getOptions()
159
    {
160
        if (!$this->options instanceof ServiceOptions) {
161
            $this->setOptions($this->serviceManager->get('zfcuser_module_options'));
0 ignored issues
show
Documentation introduced by
$this->serviceManager->g...fcuser_module_options') is of type object|array, but the function expects a object<ZfcUser\Options\U...erviceOptionsInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
162
        }
163
        return $this->options;
164
    }
165
166
    /**
167
     * set service options
168
     *
169
     * @param ServiceOptions $options
170
     */
171
    public function setOptions(ServiceOptions $options)
172
    {
173
        $this->options = $options;
174
    }
175
176
    /**
177
     * Retrieve service manager instance
178
     *
179
     * @return ServiceManager
180
     */
181
    public function getServiceManager()
182
    {
183
        return $this->serviceManager;
184
    }
185
186
    /**
187
     * Set service manager instance
188
     *
189
     * @param ServiceManager $serviceManager
190
     * @return User
191
     */
192
    public function setServiceManager(ServiceManager $serviceManager)
193
    {
194
        $this->serviceManager = $serviceManager;
195
        return $this;
196
    }
197
198
    /**
199
     * Return the Form Hydrator
200
     *
201
     * @return Hydrator
202
     */
203
    public function getFormHydrator()
204
    {
205
        if (!$this->formHydrator instanceof Hydrator) {
206
            $this->setFormHydrator(
207
                $this->serviceManager->get('zfcuser_user_hydrator')
0 ignored issues
show
Documentation introduced by
$this->serviceManager->g...zfcuser_user_hydrator') is of type object|array, but the function expects a object<ZfcUser\Mapper\HydratorInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
208
            );
209
        }
210
211
        return $this->formHydrator;
212
    }
213
214
    /**
215
     * Set the Form Hydrator to use
216
     *
217
     * @param Hydrator $formHydrator
218
     * @return User
219
     */
220
    public function setFormHydrator(Hydrator $formHydrator)
221
    {
222
        $this->formHydrator = $formHydrator;
223
        return $this;
224
    }
225
}
226