Completed
Push — develop ( f8651f...893e32 )
by greg
02:30
created

Memory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.069
c 0
b 0
f 0
cc 1
nc 1
nop 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PlaygroundGame\Form\Admin;
4
5
use PlaygroundCore\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
6
use Zend\Mvc\I18n\Translator;
7
use Zend\ServiceManager\ServiceManager;
8
9
class Memory extends Game
10
{
11
    public function __construct($name, ServiceManager $sm, Translator $translator)
12
    {
13
        $this->setServiceManager($sm);
14
        $entityManager = $sm->get('doctrine.entitymanager.orm_default');
15
16
        // having to fix a Doctrine-module bug :( https://github.com/doctrine/DoctrineModule/issues/180
17
        $hydrator = new DoctrineHydrator($entityManager, 'PlaygroundGame\Entity\Memory');
18
        $hydrator->addStrategy('partner', new \PlaygroundCore\Stdlib\Hydrator\Strategy\ObjectStrategy());
19
        $this->setHydrator($hydrator);
20
21
        parent::__construct($name, $sm, $translator);
22
23
        $this->add(array(
24
            'name' => 'victoryConditions',
25
            'type' => 'Zend\Form\Element\Text',
26
            'attributes' => array(
27
                'placeholder' => $translator->translate('% good picks vs mistakes', 'playgroundgame'),
28
                'id' => 'victoryConditions',
29
            ),
30
            'options' => array(
31
                'label' => $translator->translate('Victory conditions', 'playgroundgame'),
32
            ),
33
        ));
34
35
        // Adding an empty upload field to be able to correctly handle this on
36
        // the service side.
37
        $this->add(array(
38
            'name' => 'uploadBackImage',
39
            'attributes' => array(
40
                'type' => 'file',
41
            ),
42
            'options' => array(
43
                'label' => $translator->translate('Back card image', 'playgroundgame'),
44
            ),
45
        ));
46
        $this->add(array(
47
                'name' => 'backImage',
48
                'type' => 'Zend\Form\Element\Hidden',
49
                'attributes' => array(
50
                    'value' => '',
51
                ),
52
        ));
53
        $this->add(array(
54
            'name' => 'deleteBackImage',
55
            'type' => 'Zend\Form\Element\Hidden',
56
            'attributes' => array(
57
                'value' => '',
58
                'class' => 'delete_scratch_image',
59
            ),
60
        ));
61
    }
62
}
63