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
Pull Request — master (#1)
by Gallice
02:18
created

Image::isRemoteFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Tgallice\FBMessenger\Attachment;
4
5
use Tgallice\FBMessenger\Attachment;
6
use Tgallice\FBMessenger\ExtensionChecker;
7
8
class Image extends Attachment
9
{
10
    /**
11
     * @var bool
12
     */
13
    private $isRemoteFile;
14
15
    /**
16
     * @var string
17
     */
18
    private $path;
19
20
    /**
21
     * @param string $filePath File path of the local/remote file
22
     */
23 13
    public function __construct($filePath)
24
    {
25 13
        if (!ExtensionChecker::check($filePath, ['jpg', 'png'])) {
26 1
            throw new \InvalidArgumentException(
27 1
                sprintf('"%s" this file has not an allowed extension. Only "png" and "jpg" image are supported', $filePath)
28 1
            );
29
        }
30
31 12
        $this->isRemoteFile = preg_match('/^(https?|ftp):\/\/.*/', $filePath) === 1;
32
33 12
        if (!$this->isRemoteFile && !is_readable($filePath)) {
34 1
            throw new \InvalidArgumentException(sprintf('The file "%s" should be readable', $filePath));
35
        }
36
37 11
        $this->path = $filePath;
38 11
        $this->type = Attachment::TYPE_IMAGE;
39
40
        // Local image is sent with a multipart request
41 11
        $this->payload = [];
42
43 11
        if ($this->isRemoteFile) {
44 2
            $this->payload = [
45 2
                'url' => $this->path,
46
            ];
47 2
        }
48 11
    }
49
50
    /**
51
     * @return string
52
     */
53 1
    public function getPath()
54
    {
55 1
        return $this->path;
56
    }
57
58
    /**
59
     * @return resource
60
     */
61 2
    public function open()
62
    {
63 2
        if ($this->isRemoteFile) {
64 1
            throw new \RuntimeException('A remote file can not be open');
65
        }
66
67 1
        return fopen($this->path, 'r');
68
    }
69
70
    /**
71
     * @return bool
72
     */
73 3
    public function isRemoteFile()
74
    {
75 3
        return $this->isRemoteFile;
76
    }
77
}
78