Completed
Push — 1.x ( 6e286e...c7aa89 )
by Daniel
45:22 queued 35:25
created

ChangeEmail::createService()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 2
eloc 16
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Clayton Daley
5
 * Date: 3/10/2015
6
 * Time: 9:34 AM
7
 */
8
9
namespace ZfcUser\Factory\Form;
10
11
use Zend\Form\FormElementManager;
12
use Zend\ServiceManager\FactoryInterface;
13
use Zend\ServiceManager\ServiceLocatorInterface;
14
use ZfcUser\Form;
15
use ZfcUser\Validator;
16
17
class ChangeEmail implements FactoryInterface
18
{
19
    public function createService(ServiceLocatorInterface $formElementManager)
20
    {
21
        if ($formElementManager instanceof FormElementManager) {
22
            $sm = $formElementManager->getServiceLocator();
23
            $fem = $formElementManager;
24
        } else {
25
            $sm = $formElementManager;
26
            $fem = $sm->get('FormElementManager');
27
        }
28
29
        $options = $sm->get('zfcuser_module_options');
30
        $form = new Form\ChangeEmail(null, $options);
31
        // Inject the FormElementManager to support custom FormElements
32
        $form->getFormFactory()->setFormElementManager($fem);
0 ignored issues
show
Documentation introduced by
$fem is of type object|array, but the function expects a object<Zend\Form\FormElementManager>.

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...
33
34
        $form->setInputFilter(new Form\ChangeEmailFilter(
35
            $options,
36
            new Validator\NoRecordExists(array(
37
                'mapper' => $sm->get('zfcuser_user_mapper'),
38
                'key'    => 'email'
39
            ))
40
        ));
41
42
        return $form;
43
    }
44
}
45