Completed
Push — master ( 570da9...4be57b )
by Oscar
03:00
created

FileUpload   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getMaxSize() 0 11 2
1
<?php
2
3
namespace Folk\Formats;
4
5
use FormManager\Builder;
6
7
class FileUpload extends Loader implements FormatInterface
8
{
9
    public function __construct(Builder $builder)
10
    {
11
        parent::__construct($builder, [
12
            'loader' => $builder->file(),
13
            'field' => $builder->hidden(),
14
        ]);
15
16
        $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...
17
            'module' => 'format-upload',
18
            'max-size' => self::getMaxSize(),
19
        ]);
20
    }
21
22
    private static function getMaxSize() {
23
        $size = ini_get('upload_max_filesize');
24
25
        switch (strtoupper(substr($size, -1))) {
26
            case 'M':
27
                return intval($size) * 1000000;
28
29
            default:
30
                return intval($size);
31
        }
32
    }
33
}
34