GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 64a210...2d6991 )
by Stan
02:42
created

ProfilePhotos   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 1
cbo 9
dl 0
loc 48
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 42 4
1
<?php
2
3
namespace Teebot\Bot\Example\Command;
4
5
use Teebot\Command\AbstractCommand;
6
use Teebot\Entity\Message;
7
use Teebot\Entity\PhotoSize;
8
use Teebot\Method\GetFile;
9
use Teebot\Method\GetUserProfilePhotos;
10
use Teebot\Method\SendPhoto;
11
use Teebot\Response;
12
use Teebot\Method\SendChatAction;
13
14
class ProfilePhotos extends AbstractCommand
15
{
16
    /** @var Message */
17
    protected $entity;
18
19
    public function run()
20
    {
21
        $localPhotoPath = '/var/www/html/pic_profile_small.jpg';
22
23
        $result = (new GetUserProfilePhotos())
24
            ->setUserId($this->entity->getFrom()->getId())
25
            ->trigger();
26
27
        if ($result instanceof Response) {
28
            /** @var PhotoSize $photoWithMaxSize */
29
            $photoWithMaxSize = $result
30
                ->getFirstEntity()
31
                ->getPhotoByOffset(0)
32
                ->getPhotoSizeWithMaxFileSize();
33
34
            $result = (new GetFile())
35
                ->setFileId($photoWithMaxSize->getFileId())
36
                ->trigger();
37
38
            if ($result instanceof Response) {
39
                $downloadedFile = $result
40
                    ->getFirstEntity()
41
                    ->download('/var/www/html/pic_profile_small.jpg');
42
43
                if ($downloadedFile) {
44
                    (new SendChatAction())
45
                        ->setChatId($this->getChatId())
46
                        ->setAction(SendChatAction::ACTION_UPLOAD_PHOTO)
47
                        ->trigger();
48
49
                    sleep(2);
50
51
                    (new SendPhoto())
52
                        ->setChatId($this->getChatId())
53
                        ->setPhoto($localPhotoPath)
54
                        ->trigger();
55
56
                    unlink($localPhotoPath);
57
                }
58
            }
59
        }
60
    }
61
}
62