PushFile   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
c 4
b 0
f 0
lcom 0
cbo 3
dl 0
loc 38
ccs 11
cts 12
cp 0.9167
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getFileType() 0 11 2
1
<?php
2
3
namespace PHPushbullet\Request;
4
5
use GuzzleHttp\Client;
6
7
class PushFile extends Request
8
{
9
    /**
10
     * The type according to the Pushbullet API
11
     *
12
     * @var string $type
13
     */
14
15
    protected $type = 'file';
16
17 2
    public function __construct($file_name, $file_url, $body = null)
18
    {
19 2
        $this->parameters['file_name'] = $file_name;
20 2
        $this->parameters['file_url']  = $file_url;
21 2
        $this->parameters['file_type'] = $this->getFileType($file_url);
22 2
        $this->parameters['body']      = $body;
23 2
    }
24
25
    /**
26
     * Get the file type based on the file url
27
     *
28
     * @param string $file_url
29
     *
30
     * @return string
31
     */
32
33 2
    protected function getFileType($file_url)
34
    {
35 2
        $file_info = (new Client())->head($file_url);
36 2
        $file_type = $file_info->getHeader('content-type');
37
38 2
        if (is_array($file_type)) {
39 2
            return reset($file_type);
40
        }
41
42
        return $file_type;
43
    }
44
}
45