Completed
Pull Request — develop (#261)
by
unknown
07:50
created

EmploymentFieldset::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 58
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 58
rs 9.639
cc 1
eloc 37
nc 1
nop 0

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 Cv\Form;
4
5
use Zend\Form\Fieldset;
6
use Cv\Entity\Employment as EmploymentEntity;
7
use Core\Entity\Hydrator\EntityHydrator;
8
use Zend\InputFilter\InputFilterProviderInterface;
9
use Core\Form\ViewPartialProviderInterface;
10
use Core\Form\ViewPartialProviderTrait;
11
12
class EmploymentFieldset extends Fieldset implements InputFilterProviderInterface, ViewPartialProviderInterface
13
{
14
    
15
    use ViewPartialProviderTrait;
16
    
17
    /**
18
     * View script for rendering
19
     *
20
     * @var string
21
     */
22
    protected $defaultPartial = 'cv/form/employment';
23
    
24
    public function init()
25
    {
26
        $this->setName('employment')
27
             ->setHydrator(new EntityHydrator())
28
             ->setObject(new EmploymentEntity());
29
        
30
        $this->add(
31
            array(
32
            'type' => 'Core/Datepicker',
33
            'name' => 'startDate',
34
            'options' => array(
35
                'label' => /*@translate */ 'Start date'
36
            )
37
            )
38
        );
39
        $this->add(
40
            array(
41
            'type' => 'Core/Datepicker',
42
            'name' => 'endDate',
43
            'options' => array(
44
                'label' => /*@translate */ 'End date'
45
            )
46
            )
47
        );
48
        $this->add(
49
            array(
50
                'type' => 'checkbox',
51
                'name' => 'currentIndicator',
52
                'options' => array(
53
                        'label' => /*@translate */ 'ongoing'
54
                )
55
            )
56
        );
57
        $this->add(
58
            array(
59
                'name' => 'organizationName',
60
                'options' => array(
61
                        'label' => /*@translate */ 'Company Name'),
62
                'attributes' => array(
63
                        'title' =>  /*@translate */ 'please enter the name of the company'
64
                ),
65
            )
66
        );
67
        $this->add(
68
            array(
69
                'name' => 'description',
70
                'type' => 'Zend\Form\Element\Textarea',
71
                'options' => array(
72
                        'label' => /*@translate */ 'Description',
73
                ),
74
                'attributes' => array(
75
                        'title' => /*@translate */ 'please describe your position',
76
                ),
77
            )
78
        );
79
        
80
               
81
    }
82
    
83
    /**
84
     * @see \Zend\InputFilter\InputFilterProviderInterface::getInputFilterSpecification()
85
     */
86
    public function getInputFilterSpecification()
87
    {
88
        return [
89
            'type' => 'Cv/Employment'
90
        ];
91
    }
92
    
93
    /**
94
     * @see \Zend\Form\Form::setData()
95
     */
96 View Code Duplication
    public function populateValues($data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        if (isset($data['currentIndicator'])
99
            && isset($data['endDate'])
100
            && $data['currentIndicator']
101
        ) {
102
            // empty & hide endDate if currentIndicator is checked
103
            $data['endDate'] = '';
104
            $this->get('endDate')->setOption('rowClass', 'hidden');
105
        }
106
    
107
        return parent::populateValues($data);
108
    }
109
}
110