Passed
Pull Request — master (#52)
by Daniel
06:16
created

UploadedBase64EncodedFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 6
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 4
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\Model\Uploadable;
15
16
use Symfony\Component\HttpFoundation\File\UploadedFile;
17
18
/**
19
 * @author Shota Hoshino <[email protected]>
20
 * @author Daniel West <[email protected]>
21
 */
22
class UploadedBase64EncodedFile extends UploadedFile
23
{
24
    /**
25
     * @param string $originalName
26
     * @param null   $mimeType
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $mimeType is correct as it would always require null to be passed?
Loading history...
27
     * @param null   $size
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $size is correct as it would always require null to be passed?
Loading history...
28
     */
29
    public function __construct(Base64EncodedFile $file, $originalName = '', $mimeType = null, $size = null)
30
    {
31
        $method = new \ReflectionMethod(parent::class, '__construct');
32
        $num = $method->getNumberOfParameters();
33
        if (5 === $num) {
34
            parent::__construct($file->getPathname(), $originalName ?: $file->getFilename(), $mimeType, null, true);
35
        } else {
36
            // Symfony 4 compatible
37
            parent::__construct($file->getPathname(), $originalName ?: $file->getFilename(), $mimeType, $size, null, true);
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Component\HttpFo...adedFile::__construct() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            parent::/** @scrutinizer ignore-call */ 
38
                    __construct($file->getPathname(), $originalName ?: $file->getFilename(), $mimeType, $size, null, true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
null of type null is incompatible with the type boolean expected by parameter $test of Symfony\Component\HttpFo...adedFile::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
            parent::__construct($file->getPathname(), $originalName ?: $file->getFilename(), $mimeType, $size, /** @scrutinizer ignore-type */ null, true);
Loading history...
38
        }
39
    }
40
}
41