Completed
Pull Request — master (#268)
by greg
07:26 queued 04:08
created

Mission::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 33
rs 8.8571
cc 1
eloc 19
nc 1
nop 3
1
<?php
2
3
namespace PlaygroundGame\Form\Admin;
4
5
use Zend\Form\Form;
6
use PlaygroundCore\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
7
use Zend\Form\Element;
8
use Zend\Mvc\I18n\Translator;
9
use Zend\ServiceManager\ServiceManager;
10
use PlaygroundGame\Form\Admin\Game;
11
12
class Mission extends Game
13
{
14
    public function __construct($name, ServiceManager $sm, Translator $translator)
15
    {
16
        $this->setServiceManager($sm);
17
        $entityManager = $sm->get('doctrine.entitymanager.orm_default');
18
19
        // having to fix a Doctrine-module bug :( https://github.com/doctrine/DoctrineModule/issues/180
20
        $hydrator = new DoctrineHydrator($entityManager, 'PlaygroundGame\Entity\Mission');
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...
21
        $hydrator->addStrategy('partner', new \PlaygroundCore\Stdlib\Hydrator\Strategy\ObjectStrategy());
22
        $this->setHydrator($hydrator);
23
        
24
        /*$this->setValidationGroup(array(
25
            'MissionGame' => array(
26
                'game'
27
            )
28
        ));*/
29
30
        parent::__construct($name, $sm, $translator);
31
32
        $gameMissionFieldset = new MissionGameFieldset(null, $sm, $translator);
33
        $this->add(array(
34
            'type'    => 'Zend\Form\Element\Collection',
35
            'name'    => 'missionGames',
36
            'options' => array(
37
                'id'    => 'missionGames',
38
                'label' => $translator->translate('List of games', 'playgroundgame'),
39
                'count' => 0,
40
                'should_create_template' => true,
41
                'allow_add' => true,
42
                'allow_remove' => true,
43
                'target_element' => $gameMissionFieldset
44
            )
45
        ));
46
    }
47
}
48