Completed
Push — 1.x ( f3d5fa...00fe02 )
by Daniel
16:21 queued 16:17
created

ChangePassword::createService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 12
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
16
class ChangePassword implements FactoryInterface
17
{
18
    public function createService(ServiceLocatorInterface $formElementManager)
19
    {
20
        if ($formElementManager instanceof FormElementManager) {
0 ignored issues
show
Bug introduced by
The class Zend\Form\FormElementManager does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
21
            $sm = $formElementManager->getServiceLocator();
22
            $fem = $formElementManager;
23
        } else {
24
            $sm = $formElementManager;
25
            $fem = $sm->get('FormElementManager');
26
        }
27
28
        $options = $sm->get('zfcuser_module_options');
29
        $form = new Form\ChangePassword(null, $options);
30
        // Inject the FormElementManager to support custom FormElements
31
        $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...
32
33
        $form->setInputFilter(new Form\ChangePasswordFilter($options));
34
35
        return $form;
36
    }
37
}
38