1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * Class Nip_Form_Element_CheckboxGroup |
||||
5 | * |
||||
6 | * @method Nip_Form_Element_Checkbox[] getElements() |
||||
7 | */ |
||||
8 | class Nip_Form_Element_CheckboxGroup extends Nip_Form_Element_Input_Group |
||||
9 | { |
||||
10 | protected $_type = 'checkboxGroup'; |
||||
11 | |||||
12 | /** |
||||
13 | * @param string $requester |
||||
14 | * @return null |
||||
15 | */ |
||||
16 | public function getValue($requester = 'abstract') |
||||
0 ignored issues
–
show
|
|||||
17 | { |
||||
18 | $elements = $this->getElements(); |
||||
19 | $data = []; |
||||
20 | if ($elements) { |
||||
0 ignored issues
–
show
The expression
$elements of type Nip_Form_Element_Checkbox[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||
21 | foreach ($elements as $element) { |
||||
22 | if ($element->isChecked()) { |
||||
23 | $data[] = $element->getValue(); |
||||
24 | } |
||||
25 | } |
||||
26 | } |
||||
27 | |||||
28 | return $data; |
||||
0 ignored issues
–
show
|
|||||
29 | } |
||||
30 | |||||
31 | /** @noinspection PhpMissingParentCallCommonInspection |
||||
32 | * @inheritdoc |
||||
33 | */ |
||||
34 | public function setValue($value) |
||||
35 | { |
||||
36 | return $this->getDataFromRequest($value); |
||||
37 | } |
||||
38 | |||||
39 | /** @noinspection PhpMissingParentCallCommonInspection |
||||
40 | * @inheritdoc |
||||
41 | */ |
||||
42 | public function getDataFromRequest($request) |
||||
43 | { |
||||
44 | $elements = $this->getElements(); |
||||
45 | if (is_array($request)) { |
||||
46 | foreach ($elements as $key => $element) { |
||||
47 | $element->setChecked(in_array($key, $request)); |
||||
48 | } |
||||
49 | } else { |
||||
50 | foreach ($elements as $key => $element) { |
||||
51 | $element->setChecked(false); |
||||
52 | } |
||||
53 | } |
||||
54 | |||||
55 | return $this; |
||||
56 | } |
||||
57 | |||||
58 | /** |
||||
59 | * @return Nip\Form\Elements\AbstractElement |
||||
60 | */ |
||||
61 | public function getNewElement() |
||||
62 | { |
||||
63 | $element = $this->getForm()->getNewElement('checkbox'); |
||||
64 | $name = $this->getName(); |
||||
0 ignored issues
–
show
Are you sure the assignment to
$name is correct as $this->getName() targeting Nip\Form\Elements\AbstractElement::getName() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
65 | if (!strpos($name, '[]')) { |
||||
0 ignored issues
–
show
$name of type null is incompatible with the type string expected by parameter $haystack of strpos() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
66 | $name = $name . '[]'; |
||||
67 | } |
||||
68 | $element->setName($name); |
||||
69 | |||||
70 | return $element; |
||||
71 | } |
||||
72 | |||||
73 | /** |
||||
74 | * @return bool |
||||
75 | */ |
||||
76 | public function isRequestArray() |
||||
77 | { |
||||
78 | return true; |
||||
79 | } |
||||
80 | } |
||||
81 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.