Completed
Push — master ( e9be36...9488e8 )
by Camilo
04:57
created

InputFile::setStream()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Telegram\Types\Custom;
6
7
use unreal4u\TelegramAPI\Exceptions\FileNotReadable;
8
9
/**
10
 * This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual
11
 * way that files are uploaded via the browser.
12
 *
13
 * @see https://core.telegram.org/bots/api#inputfile
14
 */
15
class InputFile
16
{
17
    /**
18
     * The path of the file
19
     * @var string
20
     */
21
    public $path = '';
22
23
    /**
24
     * The actual stream to the file
25
     * @var int
26
     */
27
    private $stream = null;
28
29 5
    public function __construct(string $path)
30
    {
31 5
        $this->path = $path;
32 5
        $this->setStream();
33 4
    }
34
35
    /**
36
     * Will setup the stream
37
     *
38
     * @return InputFile
39
     */
40 5
    private function setStream(): InputFile
41
    {
42 5
        if (is_readable($this->path)) {
43 4
            $this->stream = fopen($this->path, 'r');
0 ignored issues
show
Documentation Bug introduced by
It seems like fopen($this->path, 'r') of type resource is incompatible with the declared type integer of property $stream.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
        } else {
45 1
            throw new FileNotReadable(sprintf('Can not read %s, please check', $this->path));
46
        }
47
48 4
        return $this;
49
    }
50
51 4
    public function getStream()
52
    {
53 4
        $this->setStream();
54 4
        return $this->stream;
55
    }
56
}
57