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

InputFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 42
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setStream() 0 10 2
A getStream() 0 5 1
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