Downloadable   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 11
c 1
b 0
f 0
dl 0
loc 17
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A download() 0 12 1
1
<?php
2
3
4
namespace Sysbot\Telegram\ExtendedTypes;
5
6
7
use GuzzleHttp\Promise\PromiseInterface;
8
use Psr\Http\Message\StreamInterface;
9
use Sysbot\Telegram\Types\File;
10
11
trait Downloadable
12
{
13
14
    use BaseType;
15
16
    public function download(string $path): PromiseInterface
17
    {
18
        $fileId = $this->bigFileId ?? $this->smallFileId ?? $this->audioFileId ?? $this->documentFileId ??
19
            $this->gifFileId ?? $this->mpeg4FileId ?? $this->photoFileId ?? $this->stickerFileId ?? $this->videoFileId ??
20
            $this->voiceFileId ?? $this->fileId;
21
        return $this->api->getFile($fileId)->then(
22
            function (File $file) {
23
                return $this->api->downloadFile($file->filePath);
24
            }
25
        )->then(
26
            function (StreamInterface $stream) use ($path) {
27
                return file_put_contents($path, $stream);
28
            }
29
        );
30
    }
31
}