Issues (138)

src/Elements/File.php (2 issues)

1
<?php
2
3
class Nip_Form_Element_File extends Nip_Form_Element_Input_Abstract
4
{
5
    protected $_value = null;
6
7
    public function init()
8
    {
9
        parent::init();
10
        $this->setAttrib('type', 'file');
11
        $this->getForm()->setAttrib('enctype', 'multipart/form-data');
12
    }
13
14
    public function getValue($requester = 'abstract')
0 ignored issues
show
The parameter $requester is not used and could be removed. ( Ignorable by Annotation )

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

14
    public function getValue(/** @scrutinizer ignore-unused */ $requester = 'abstract')

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

Loading history...
15
    {
16
        if ($this->_value == null) {
17
            $this->_value = $this->generateValueFromRequest();
18
        }
19
20
        return $this->_value;
21
    }
22
23
    /**
24
     * @return array|false|mixed
25
     */
26
    protected function generateValueFromRequest()
27
    {
28
        $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 getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
29
        $name = str_replace(']', '', $name);
30
        $parts = explode('[', $name);
31
32
        if (count($parts) <= 1) {
33
            return isset($_FILES[$name]) ? $_FILES[$name] : false;
34
        }
35
36
        if (!isset($_FILES[$parts[0]])) {
37
            return false;
38
        }
39
        $fileData = [];
40
        foreach ($_FILES[$parts[0]] as $key=>$data) {
41
            $fileData[$key] = $data[$parts[1]];
42
        }
43
        return $fileData;
44
    }
45
}
46