Completed
Push — master ( 8431a9...0bccd4 )
by Gabriel
04:28
created

Nip_Form_Element_File::getValue()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
ccs 0
cts 14
cp 0
rs 9.2248
cc 5
nc 4
nop 1
crap 30
1
<?php
2
3
class Nip_Form_Element_File extends Nip_Form_Element_Input_Abstract
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    protected $_value;
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
Unused Code introduced by
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) {
17
            $name = $this->getName();
0 ignored issues
show
Bug introduced by
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...
18
            $name = str_replace(']', '', $name);
19
            $parts = explode('[', $name);
20
21
            if (count($parts) > 1) {
22
                if ($_FILES[$parts[0]]) {
23
                    $fileData = [];
24
                    foreach ($_FILES[$parts[0]] as $key=>$data) {
25
                        $fileData[$key] = $data[$parts[1]];
26
                    }
27
                    $this->_value = $fileData;
28
                } else {
29
                    $this->_value = null;
30
                }
31
            } else {
32
                $this->_value = $_FILES[$name];
33
            }
34
        }
35
36
        return $this->_value;
37
    }
38
}
39