FormPlainControl   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A init() 0 15 2
1
<?php
2
3
/*
4
 * Copyright (C) 2015-2016 Michael Herold <[email protected]>
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace hemio\form\template;
21
22
use hemio\form\Abstract_;
23
use hemio\html\Interface_\Submittable;
24
25
/**
26
 * Just the control element without any label etc.
27
 *
28
 * @author Michael Herold <[email protected]>
29
 */
30
class FormPlainControl extends \hemio\form\Abstract_\TemplateFormField {
31
32
    public function __construct() {
33
        $this->setPostInitHook(function ($null) {
0 ignored issues
show
Unused Code introduced by
The parameter $null is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
            return;
35
        });
36
    }
37
38
    public function init(Abstract_\FormField $field, Submittable $control) {
39
        $this->setControl($control);
40
        $this->setField($field);
41
42
        if (!$control->getAttribute('title'))
43
            $control->setAttribute('title', $field->title);
0 ignored issues
show
Bug introduced by
The property title does not seem to exist in hemio\form\Abstract_\FormField.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
44
45
        $control->setAttribute('name', $field->getHtmlName());
46
        $control->setId($field->getHtmlId());
47
48
        $this->addChild($control);
0 ignored issues
show
Unused Code introduced by
The call to the method hemio\form\template\FormPlainControl::addChild() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
49
50
        $hook = $this->postInitHook;
51
        $hook($this);
52
    }
53
54
}
55