Completed
Push — master ( fbac60...3b23d7 )
by Camilo
14s
created

TelegramDocument   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 44
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A __toString() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\InternalFunctionality;
6
7
/**
8
 * Used when we download a file from Telegram, contains some important headers information that else would be lost
9
 */
10
class TelegramDocument
11
{
12
    /**
13
     * The mime type of this file
14
     * @var string
15
     */
16
    public $mime_type = '';
17
18
    /**
19
     * The actual contents of this file
20
     * @var string
21
     */
22
    public $contents = '';
23
24
    /**
25
     * The file size
26
     * @var int
27
     */
28
    public $file_size = 0;
29
30
    /**
31
     * Constructs a representable document
32
     *
33
     * @param TelegramResponse $response
34
     */
35 1
    public function __construct(TelegramResponse $response)
36
    {
37 1
        $headers = $response->getHeaders();
38
        // What better to get the mime type than what the Telegram servers already send us?
39 1
        $this->mime_type = $headers['Content-Type'][0];
40
        // Same with file length
41 1
        $this->file_size = (int)$headers['Content-Length'][0];
42 1
        $this->contents = (string)$response->getResultString();
43 1
    }
44
45
    /**
46
     * When called with string-ish functions, assume we want the actual contents of the file
47
     * @return string
48
     */
49 1
    public function __toString()
50
    {
51 1
        return $this->contents;
52
    }
53
}
54