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

Stream   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A download() 0 21 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