Completed
Push — master ( c47098...bd2863 )
by Shcherbak
37:44 queued 22:47
created

Checkbox::unCheck()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
  namespace Fiv\Form\Element;
4
5
  use Fiv\Form\Element;
6
7
  /**
8
   * Generate <input type="submit" /> element
9
   *
10
   * @author Ivan Shcherbak <[email protected]>
11
   * @package Fiv\Form
12
   */
13
  class Checkbox extends Element\Input {
14
15
    /**
16
     * @var int
17
     */
18
    protected $value = 1;
19
20
    /**
21
     * @var string
22
     */
23
    protected $label = '';
24
25
    /**
26
     * @var array
27
     */
28
    protected $attributes = [
29
      'type' => 'checkbox',
30
    ];
31
32
    /**
33
     * Value in checkbox can be true or false
34
     *
35
     * @param int|boolean $value
36
     * @return $this
37
     */
38
    public function setValue($value) {
39
      if (!empty($value)) {
40
        return $this->check();
41
      } else {
42
        return $this->unCheck();
43
      }
44
45
    }
46
47
48
    /**
49
     * @return $this
50
     */
51
    public function check() {
52
      $this->setAttribute('checked', 'checked');
53
      parent::setValue(1);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setValue() instead of check()). Are you sure this is correct? If so, you might want to change this to $this->setValue().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
54
      return $this;
55
    }
56
57
58
    /**
59
     * Set value to 0
60
     * @return $this
61
     */
62
    public function unCheck() {
63
      $this->removeAttribute('checked');
64
      parent::setValue(0);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setValue() instead of unCheck()). Are you sure this is correct? If so, you might want to change this to $this->setValue().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
65
      return $this;
66
    }
67
68
69
    /**
70
     * @param string $text
71
     * @return $this
72
     */
73
    public function setLabel($text) {
74
      $this->label = $text;
75
      return $this;
76
    }
77
78
79
    /**
80
     * @return string
81
     */
82
    public function render() {
83
      return '<label>' . parent::render() . $this->label . '</label>';
84
    }
85
86
  }