Completed
Push — develop ( bfc0af...88d3fd )
by
unknown
08:28
created

EducationFieldset   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 141
Duplicated Lines 9.22 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 99 1
A getInputFilterSpecification() 0 6 1
A populateValues() 13 13 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Cv\Form;
4
5
use Zend\Form\Fieldset;
6
use Cv\Entity\Education as EducationEntity;
7
use Core\Entity\Hydrator\EntityHydrator;
8
use Zend\InputFilter\InputFilterProviderInterface;
9
use Core\Form\ViewPartialProviderInterface;
10
use Core\Form\ViewPartialProviderTrait;
11
12
class EducationFieldset 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/education';
23
    
24
    public function init()
25
    {
26
        $this->setName('education')
27
             ->setHydrator(new EntityHydrator())
28
             ->setObject(new EducationEntity());
29
        
30
        $this->add(
31
            array(
32
            'type' => 'Core/Datepicker',
33
            'name' => 'startDate',
34
            'options' => array(
35
                'label' => /*@translate*/ 'Start date',
36
                'data-width' => '50%',
37
                'class' => 'selectpicker'
38
            )
39
            )
40
        );
41
        $this->add(
42
            array(
43
            'type' => 'Core/Datepicker',
44
            'name' => 'endDate',
45
            'options' => array(
46
                'label' => /*@translate*/ 'End date'
47
            )
48
            )
49
        );
50
        $this->add(
51
            array(
52
                'type' => 'checkbox',
53
                'name' => 'currentIndicator',
54
                'options' => array(
55
                        'label' => /*@translate */ 'ongoing'
56
                )
57
            )
58
        );
59
        
60
        $this->add(
61
            array(
62
                'name' => 'competencyName',
63
                'options' => array(
64
                        'label' => /*@translate */ 'Degree'),
65
                'attributes' => array(
66
                        //'id' => 'education-competencyname',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
                        'title' =>  /*@translate */ 'please enter the name of your qualification'
68
                ),
69
            )
70
        );
71
        
72
        $this->add(
73
            array(
74
                'name' => 'organizationName',
75
                'options' => array(
76
                        'label' => /*@translate */ 'Organization Name'),
77
                'attributes' => array(
78
                        //'id' => 'education-organizationname',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
79
                        'title' =>  /*@translate */ 'please enter the name of the university or school'
80
                ),
81
            )
82
        );
83
84
        $this->add(
85
            array(
86
                'name' => 'country',
87
                'options' => array(
88
                        'label' => /*@translate */ 'Country'),
89
                'attributes' => array(
90
                        //'id' => 'education-country',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
91
                        'title' => /*@translate */ 'please select the country'
92
                ),
93
            )
94
        );
95
        
96
        $this->add(
97
            array(
98
                'name' => 'city',
99
                'options' => array(
100
                        'label' => /*@translate */ 'City'),
101
                'attributes' => array(
102
                        //'id' => 'education-city',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
103
                        'title' => /*@translate */ 'please enter the name of the city'
104
                ),
105
            )
106
        );
107
        
108
        $this->add(
109
            array(
110
                'name' => 'description',
111
                'type' => 'Zend\Form\Element\Textarea',
112
                'options' => array(
113
                        'label' => /*@translate */ 'Description',
114
                ),
115
                'attributes' => array(
116
                        //'id' => 'education-description',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
117
                        'title' => /*@translate */ 'please enter a description',
118
                ),
119
            )
120
        );
121
               
122
    }
123
124
    /**
125
     *
126
     * @see \Zend\InputFilter\InputFilterProviderInterface::getInputFilterSpecification()
127
     */
128
    public function getInputFilterSpecification()
129
    {
130
        return [
131
            'type' => 'Cv/Education'
132
        ];
133
    }
134
135
    /**
136
     *
137
     * @see \Zend\Form\Form::setData()
138
     */
139 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...
140
    {
141
        if (isset($data['currentIndicator'])
142
            && isset($data['endDate'])
143
            && $data['currentIndicator']
144
        ) {
145
            // empty & hide endDate if currentIndicator is checked
146
            $data['endDate'] = '';
147
            $this->get('endDate')->setOption('rowClass', 'hidden');
148
        }
149
        
150
        return parent::populateValues($data);
151
    }
152
}
153