File   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 6
dl 0
loc 48
ccs 27
cts 27
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B prepareUploadHandlers() 0 28 6
A getDefaultSpecs() 0 7 1
1
<?php
2
namespace Sirius\Input\Element\Input;
3
4
use Sirius\Input\Element\Input as BaseInput;
5
use Sirius\Input\Traits\HasUploadTrait;
6
use Sirius\Input\InputFilter;
7
use Sirius\Upload\Handler;
8
use Sirius\Input\Specs;
9
10
/**
11
 * File element
12
 */
13
class File extends BaseInput
14
{
15
16
    use HasUploadTrait;
17
18 3
    protected function getDefaultSpecs()
19
    {
20
21
        return array(
22 3
            Specs::WIDGET => 'file'
23 3
        );
24
    }
25
26
    /**
27
     * Attaches the upload handlers to the input object
28
     *
29
     * @param InputFilter $inputFilter
30
     */
31 1
    protected function prepareUploadHandlers(InputFilter $inputFilter)
32
    {
33 1
        $uploadValidator = new \Sirius\Validation\ValueValidator(
34 1
            $inputFilter->getValidator()->getRuleFactory(),
35 1
            $inputFilter->getValidator()->getErroMessagePrototype(),
36 1
            $this->getLabel()
37 1
        );
38
39
        // create the upload handler
40 1
        $uploadHandler = new Handler(
41 1
            $this->getUploadContainer(),
42 1
            $this->getUploadOptions(),
0 ignored issues
show
Bug introduced by
It seems like $this->getUploadOptions() targeting Sirius\Input\Traits\HasU...ait::getUploadOptions() can also be of type null; however, Sirius\Upload\Handler::__construct() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
43
            $uploadValidator
44 1
        );
45 1
        if (is_array($this->getUploadRules())) {
46 1
            foreach ($this->getUploadRules() as $rule) {
47 1
                if ( ! is_array($rule)) {
48 1
                    $rule = array( $rule );
49 1
                }
50 1
                $name    = $rule[0];
51 1
                $options = isset($rule[1]) ? $rule[1] : null;
52 1
                $message = isset($rule[2]) ? $rule[2] : null;
53 1
                $label   = $this->getLabel();
54 1
                $uploadHandler->addRule($name, $options, $message, $label);
55 1
            }
56 1
        }
57 1
        $inputFilter->setUploadHandler($inputFilter->getUploadPrefix() . $this->getName(), $uploadHandler);
58 1
    }
59
60
}
61