Completed
Push — master ( 087a37...e6eaf2 )
by Oscar
02:56
created

FileUpload::val()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Folk\Formats;
4
5
use FormManager\Builder;
6
use SplFileInfo;
7
8
class FileUpload extends Loader implements FormatInterface
9
{
10
    public function __construct(Builder $builder)
11
    {
12
        parent::__construct($builder, [
13
            'loader' => $builder->file(),
14
            'field' => $builder->hidden(),
15
        ]);
16
17
        $this->data([
0 ignored issues
show
Documentation introduced by
array('module' => 'forma... => self::getMaxSize()) is of type array<string,string|inte...,"max-size":"integer"}>, but the function expects a null|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
18
            'module' => 'format-upload',
19
            'max-size' => self::getMaxSize(),
20
        ]);
21
    }
22
23
    private static function getMaxSize() {
24
        $size = ini_get('upload_max_filesize');
25
26
        switch (strtoupper(substr($size, -1))) {
27
            case 'M':
28
                return intval($size) * 1000000;
29
30
            default:
31
                return intval($size);
32
        }
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function val($value = null)
39
    {
40
        if ($value instanceof SplFileInfo) {
41
            $value = $value->getFileName();
42
        }
43
44
        return parent::val($value);
45
    }
46
}
47