Completed
Push — master ( 9b439e...de8363 )
by Igor
03:05
created

Decoder::createFromPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 15
nc 3
nop 6
crap 3
1
<?php
2
3
/**
4
 * @link https://github.com/rkit/filemanager-yii2
5
 * @copyright Copyright (c) 2015 Igor Romanov
6
 * @license [MIT](http://opensource.org/licenses/MIT)
7
 */
8
9
namespace rkit\filemanager;
10
11
use yii\base\InvalidValueException;
12
use rkit\filemanager\models\File;
13
14
/**
15
 * File Manager
16
 *
17
 * @author Igor Romanov <[email protected]>
18
 * @since 1.0
19
 */
20
class Decoder
21
{
22
    /**
23
     * Create file from uploader (UploadedFile)
24
     *
25
     * @param Storage $storage;
0 ignored issues
show
Documentation introduced by
There is no parameter named $storage;. Did you maybe mean $storage?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
26
     * @param string $path Path to the file
27
     * @param int $ownerId
28
     * @param int $ownerType
29
     * @param bool $temporary The file is temporary
30
     * @param bool $protected The file is protected, not available from the web
31
     * @return \rkit\filemanager\models\File|bool
32
     */
33 31
    public function createFromUploader(
34
        $storage,
35
        $path,
36
        $ownerId = -1,
37
        $ownerType = -1,
38
        $temporary = false,
39
        $protected = false
40
    ) {
41 31
        $file = File::create($path, $ownerId, $ownerType, $temporary, $protected);
42 31
        if ($file) {
43 30
            $file->setStorage($storage);
44 30
            return $file->getStorage()->save($path);
45
        }
46
47 1
        throw new InvalidValueException('Unable to create from `' . $path . '`');
48
    }
49
50
    /**
51
     * Create file from path
52
     *
53
     * @param Storage $storage;
0 ignored issues
show
Documentation introduced by
There is no parameter named $storage;. Did you maybe mean $storage?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
54
     * @param string $path Path to the file or URL
55
     * @param int $ownerId
56
     * @param int $ownerType
57
     * @param bool $temporary The file is temporary
58
     * @param bool $protected The file is protected, not available from the web
59
     * @return \rkit\filemanager\models\File|bool
60
     */
61 5
    public function createFromPath(
62
        $storage,
63
        $path,
64
        $ownerId = -1,
65
        $ownerType = -1,
66
        $temporary = false,
67
        $protected = false
68
    ) {
69 5
        $filePath = tempnam(sys_get_temp_dir(), 'FMR');
70 5
        if ($fileContent = @file_get_contents($path)) {
71 4
            file_put_contents($filePath, $fileContent);
72 4
            $file = File::create($filePath, $ownerId, $ownerType, $temporary, $protected);
73 4
            if ($file) {
74 4
                $file->setStorage($storage);
75 4
                return $file->getStorage()->save($filePath, false);
0 ignored issues
show
Unused Code introduced by
The call to Storage::save() has too many arguments starting with false.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
76
            }
77
        } // @codeCoverageIgnore
78
79 1
        throw new InvalidValueException('Unable to create from `' . $path . '`');
80
    }
81
}
82