Passed
Push — master ( a22205...112e67 )
by Gabriel
04:04 queued 13s
created

AbstractForm::getButton()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 1
crap 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A AbstractForm::getCache() 0 3 1
1
<?php
2
3
namespace Nip\Form;
4
5
use Nip\Form\Elements\AbstractElement as ElementAbstract;
6
use Nip\View;
7
8
/**
9
 * Class AbstractForm
10
 *
11
 */
12
abstract class AbstractForm
13
{
14
    use Traits\DataProcessingTrait;
15
    use Traits\HasAttributesTrait;
16
    use Traits\HasButtonsTrait;
17
    use Traits\HasClassTrait;
18
    use Traits\HasDisplayGroupsTrait;
19
    use Traits\HasElementsTrait;
20
    use Traits\HasErrorsTrait;
21
    use Traits\HasExecutionMethodsTrait;
22
    use Traits\HasRendererTrait;
23
    use Traits\MagicMethodElementsFormTrait;
24
    use Traits\MessagesTrait;
25
    use Traits\NewElementsMethods;
26
27
    const ENCTYPE_URLENCODED = 'application/x-www-form-urlencoded';
28
    const ENCTYPE_MULTIPART = 'multipart/form-data';
29
30
    /**
31
     * @var array
32
     */
33
    protected $methods = ['delete', 'get', 'post', 'put'];
34
35
    protected $_options = [];
36
37
    protected $_decorators = [];
38
    protected $_cache;
39
40
    protected $controllerView = false;
41
42
    /**
43
     * AbstractForm constructor.
44
     */
45 26
    public function __construct()
46
    {
47 26
        $this->init();
48 26
        $this->postInit();
49 26
    }
50
51 26
    public function init()
52
    {
53 26
        $this->initAction();
54 26
    }
55
56 26
    protected function initAction()
57
    {
58 26
        if (function_exists('current_url')) {
59
            $this->setAction(current_url());
60
        }
61 26
    }
62
63
    /**
64
     * @param string $action
65
     * @return AbstractForm
66
     */
67
    public function setAction($action)
68
    {
69
        return $this->setAttrib('action', (string)$action);
70
    }
71
72 26
    public function postInit()
73
    {
74 26
    }
75
76
    /**
77
     * @param $name
78
     * @return ElementAbstract|null
79
     */
80 1
    public function __get($name)
81
    {
82 1
        $element = $this->getElement($name);
83 1
        if ($element) {
0 ignored issues
show
introduced by
$element is of type Nip\Form\Elements\AbstractElement, thus it always evaluated to true.
Loading history...
84 1
            return $element;
85
        }
86
87
        return null;
88
    }
89
90
    /**
91
     * @param $key
92
     * @param $value
93
     * @return $this
94
     */
95
    public function setOption($key, $value)
96
    {
97
        $key = (string)$key;
98
        $this->_options[$key] = $value;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @param string $key
105
     * @return mixed|null
106
     */
107
    public function getOption($key)
108
    {
109
        $key = (string)$key;
110
        if (!isset($this->_options[$key])) {
111
            return null;
112
        }
113
114
        return $this->_options[$key];
115
    }
116
117
    /**
118
     * @param $method
119
     * @return AbstractForm
120
     */
121
    public function setMethod($method)
122
    {
123
        if (in_array($method, $this->methods)) {
124
            return $this->setAttrib('method', $method);
125
        }
126
        trigger_error('Method is not valid', E_USER_ERROR);
127
128
        return null;
129
    }
130
131
132
    /**
133
     * @param $key
134
     * @return mixed
135
     */
136 11
    public function getCache($key)
137
    {
138 11
        return $this->_cache[$key];
139
    }
140
141
    /**
142
     * @param string $key
143
     * @param $value
144
     */
145 11
    public function setCache($key, $value)
146
    {
147 11
        $this->_cache[$key] = $value;
148 11
    }
149
150
    /**
151
     * @param $key
152
     * @return bool
153
     */
154
    public function isCache($key)
155
    {
156
        return isset($this->_cache[$key]);
157
    }
158
159
    /**
160
     * @return string
161
     */
162
    public function getName()
163
    {
164
        return get_class($this);
165
    }
166
167
    /**
168
     * @return View|null
169
     */
170
    public function getControllerView()
171
    {
172
        if (!$this->controllerView) {
173
            $this->controllerView = app('kernel')->getDispatcher()->getCurrentController()->getView();
0 ignored issues
show
Bug introduced by
The method getDispatcher() does not exist on Nip\Container\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
            $this->controllerView = app('kernel')->/** @scrutinizer ignore-call */ getDispatcher()->getCurrentController()->getView();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
The call to app() has too many arguments starting with 'kernel'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
            $this->controllerView = /** @scrutinizer ignore-call */ app('kernel')->getDispatcher()->getCurrentController()->getView();

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
174
        }
175
176
        return $this->controllerView;
177
    }
178
}
179