Passed
Push — master ( 09050d...6a0831 )
by Бабичев
04:00
created

Stream::download()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 21
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 9.0534
c 1
b 0
f 0
cc 4
eloc 8
nc 3
nop 2
crap 4
1
<?php
2
3
namespace Bavix\Helpers;
4
5
use Bavix\Exceptions;
6
use Bavix\Exceptions\NotFound;
7
8
class Stream
9
{
10
11
    /**
12
     * @param string $from
13
     * @param string $to
14
     *
15
     * @return bool
16
     *
17
     * @throws Exceptions\PermissionDenied
18
     * @throws NotFound\Path
19
     */
20 3
    public static function download($from, $to)
21
    {
22
        /**
23
         * @var bool|resource $fromStream
24
         */
25 3
        $fromStream = File::open($from);
26
27 3
        if (!$fromStream)
28
        {
29 1
            throw new NotFound\Path('Stream `' . $from . '` not found');
30
        }
31
32 2
        if (!File::real($to) && !File::touch($to))
33
        {
34 1
            throw new Exceptions\PermissionDenied('File `' . $to . '`');
35
        }
36
37 1
        File::put($to, $fromStream);
38
39 1
        return File::close($fromStream);
0 ignored issues
show
Documentation introduced by
$fromStream is of type boolean, but the function expects a resource.

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...
40
    }
41
42
}
43