Completed
Push — develop ( c603db...77b219 )
by
unknown
16:24 queued 08:23
created

UserStatusFieldset   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 25.93 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setViewPartial() 0 6 1
A getViewPartial() 0 4 1
A getHydrator() 0 9 2
A setStatusOptions() 0 6 1
A init() 21 21 1

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
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license       MIT
8
 */
9
10
namespace Auth\Form;
11
12
use Core\Entity\Hydrator\EntityHydrator;
13
use Zend\Form\Fieldset;
14
use Core\Form\ViewPartialProviderInterface;
15
16
class UserStatusFieldset extends Fieldset implements ViewPartialProviderInterface
17
{
18
19
    /**
20
     * View script for rendering
21
     *
22
     * @var string
23
     */
24
    protected $viewPartial = 'form/auth/status';
25
    
26
    /**
27
     * @var array
28
     */
29
    protected $statusOptions = [];
30
31
    /**
32
     * @param String $partial
33
     *
34
     * @return $this
35
     */
36
    public function setViewPartial($partial)
37
    {
38
        $this->viewPartial = $partial;
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getViewPartial()
47
    {
48
        return $this->viewPartial;
49
    }
50
51
    /**
52
     * @return \Zend\Hydrator\HydratorInterface
53
     */
54
    public function getHydrator()
55
    {
56
        if (!$this->hydrator) {
57
            $hydrator = new EntityHydrator();
58
            $this->setHydrator($hydrator);
59
        }
60
61
        return $this->hydrator;
62
    }
63
64
    /**
65
	 * @param array $statusOptions
66
	 * @return UserStatusFieldset
67
	 */
68
	public function setStatusOptions(array $statusOptions)
69
	{
70
		$this->statusOptions = $statusOptions;
71
		
72
		return $this;
73
	}
74
75 View Code Duplication
	public function init()
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...
76
    {
77
        $this->setName('status');
78
79
        $this->add(
80
            [
81
                'name'       => 'status',
82
                'type'       => 'Zend\Form\Element\Select',
83
                'options'    => [
84
                    'label'         => /*@translate */ 'Status',
85
                    'value_options' => $this->statusOptions
86
                ],
87
                'attributes' => [
88
                    'data-placeholder' => /*@translate*/ 'please select',
89
                    'data-allowclear' => 'false',
90
                    'data-searchbox' => -1,  // hide the search box
91
                    'required' => true, // mark label as required
92
                ],
93
            ]
94
        );
95
    }
96
}
97