Completed
Push — master ( b08b67...b98ff3 )
by greg
10:52 queued 07:23
created

MissionGameFieldset   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
c 2
b 1
f 0
lcom 0
cbo 6
dl 0
loc 72
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 64 1
A getInputFilterSpecification() 0 4 1
1
<?php
2
3
namespace PlaygroundGame\Form\Admin;
4
5
use PlaygroundGame\Entity\MissionGame;
6
use Zend\Form\Fieldset;
7
use Zend\Mvc\I18n\Translator;
8
use PlaygroundCore\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
9
use Zend\ServiceManager\ServiceManager;
10
use Zend\InputFilter\InputFilterProviderInterface;
11
12
class MissionGameFieldset extends Fieldset implements InputFilterProviderInterface
13
{
14
    public function __construct($name, ServiceManager $serviceManager, Translator $translator)
15
    {
16
        parent::__construct($name);
17
        $entityManager = $serviceManager->get('doctrine.entitymanager.orm_default');
18
19
        $this->setHydrator(new DoctrineHydrator($entityManager, 'PlaygroundGame\Entity\MissionGame'))
0 ignored issues
show
Documentation introduced by
$entityManager is of type object|array, but the function expects a object<Doctrine\Common\Persistence\ObjectManager>.

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...
20
        ->setObject(new MissionGame());
21
22
        $this->add(array(
23
            'type' => 'Zend\Form\Element\Hidden',
24
            'name' => 'id'
25
        ));
26
27
        $this->add(array(
28
            'name' => 'game',
29
            'type' => 'DoctrineModule\Form\Element\ObjectSelect',
30
            'options' => array(
31
                'empty_option' => $translator->translate('Select a game', 'playgroundgame'),
32
                'label' => $translator->translate('Game', 'playgroundgame'),
33
                'object_manager' => $entityManager,
34
                'target_class' => 'PlaygroundGame\Entity\Game',
35
                'property' => 'title'
36
            ),
37
            'attributes' => array(
38
                'required' => false,
39
                //'multiple' => 'multiple',
40
            )
41
        ));
42
        
43
        $this->add(array(
44
            'type' => 'Zend\Form\Element\Hidden',
45
            'name' => 'position',
46
            'attributes' =>  array(
47
                'id' => 'position__index__',
48
            ),
49
        ));
50
        
51
        $gameMissionConditionFieldset = new MissionGameConditionFieldset(null, $serviceManager, $translator);
52
        $this->add(array(
53
            'type'    => 'Zend\Form\Element\Collection',
54
            'name'    => 'conditions',
55
            'options' => array(
56
                'id'    => 'conditions',
57
                'label' => $translator->translate('List of conditions', 'playgroundgame'),
58
                'count' => 0,
59
                'should_create_template' => true,
60
                'allow_add' => true,
61
                'allow_remove' => true,
62
                'target_element' => $gameMissionConditionFieldset
63
            )
64
        ));
65
        
66
        $this->add(array(
67
            'type' => 'Zend\Form\Element\Button',
68
            'name' => 'add_condition',
69
            'options' => array(
70
                'label' => $translator->translate('Add Condition', 'playgroundgame'),
71
            ),
72
            'attributes' => array(
73
                'class' => 'addCondition',
74
            )
75
        ));
76
77
    }
78
    
79
    public function getInputFilterSpecification()
80
    {
81
        return array('game' => array('required' => true));
82
    }
83
}
84