Media   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 31
ccs 19
cts 19
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDataUri() 0 3 1
A getContentType() 0 3 1
A getBinaryString() 0 3 1
A save() 0 5 2
1
<?php
2
3
namespace mpyw\Cowitter;
4
5
class Media implements MediaInterface
6
{
7
    protected $contentType;
8
    protected $data;
9
10 1
    public function __construct($content_type, $data)
11 1
    {
12 1
        $this->contentType = $content_type;
13 1
        $this->data = $data;
14 1
    }
15
16 1
    public function getContentType()
17 1
    {
18 1
        return $this->contentType;
19
    }
20
21 1
    public function getBinaryString()
22 1
    {
23 1
        return $this->data;
24
    }
25
26 1
    public function getDataUri()
27 1
    {
28 1
        return 'data:' . $this->contentType . ';base64,' . base64_encode($this->data);
29
    }
30
31 1
    public function save($path)
32 1
    {
33 1
        if (@file_put_contents($path, $this->data) === false) {
34 1
            $error = error_get_last();
35 1
            throw new \RuntimeException($error['message']);
36
        }
37 1
    }
38
}
39