Completed
Push — develop ( dfd31d...f6e11d )
by
unknown
25:04 queued 17:04
created

FormAbstract   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 9
c 2
b 2
f 0
lcom 2
cbo 4
dl 0
loc 74
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getHydrator() 0 8 2
A getPlugin() 0 14 3
A init() 0 22 2
getCoreFieldset() 0 1 ?
A factory() 0 4 1
1
<?php
2
3
namespace Settings\Form;
4
5
use Zend\ServiceManager\ServiceLocatorInterface;
6
use Zend\Form\Form;
7
use Zend\Hydrator\ArraySerializable;
8
9
abstract class FormAbstract extends Form
0 ignored issues
show
Coding Style introduced by
FormAbstract does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
10
{
11
    
12
    /**
13
     * @var ServiceLocatorInterface
14
     */
15
    protected $formManager;
16
17
    public function __construct(ServiceLocatorInterface $formManager, $name = null)
18
    {
19
        parent::__construct('settings');
20
        $this->formManager = $formManager;
21
        $this->setAttribute('method', 'post');
22
                $this->setBindOnValidate(Form::BIND_ON_VALIDATE);
23
    }
24
25
    public function getHydrator()
26
    {
27
        if (!$this->hydrator) {
28
            $hydrator = new ArraySerializable();
29
            $this->setHydrator($hydrator);
30
        }
31
        return $this->hydrator;
32
    }
33
    
34
    protected function getPlugin($name)
35
    {
36
        $plugin = null;
37
        $factory = $this->getFormFactory();
38
        $formElementManager = $factory->getFormElementManager();
39
        if (isset($formElementManager)) {
40
            $serviceLocator = $formElementManager->getServiceLocator();
41
            $viewhelpermanager = $serviceLocator->get('viewhelpermanager');
42
            if (isset($viewhelpermanager)) {
43
                $plugin = $viewhelpermanager->get($name);
44
            }
45
        }
46
        return $plugin;
47
    }
48
49
    public function init()
50
    {
51
52
        $this->setName('setting-core');
53
        
54
        $pluginUrl = $this->getPlugin('url');
55
        $url = call_user_func_array($pluginUrl, array(null, array(), null, true));
56
        $this->setAttribute('action', $url);
57
        
58
        //->setHydrator(new ModelHydrator())
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...
59
        //->setObject(new SettingsEntity());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
60
        
61
        $coreFieldset = $this->getCoreFieldset();
62
        if (isset($coreFieldset)) {
63
            $this->add(
64
                $this->formManager->get($coreFieldset)
65
                            ->setUseAsBaseFieldset(true)
66
            );
67
        }
68
                
69
        $this->add($this->formManager->get('DefaultButtonsFieldset'));
70
    }
71
    
72
    abstract public function getCoreFieldset();
73
    
74
    /**
75
     * @param ServiceLocatorInterface $formManager
76
     * @return FormAbstract
77
     */
78
    public static function factory(ServiceLocatorInterface $formManager)
79
    {
80
        return new static($formManager);
81
    }
82
}
83