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

FileUpload   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 0
cbo 1
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getMaxSize() 0 11 2
A val() 0 8 2
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