Completed
Push — master ( 3cf178...59e65f )
by Ryosuke
03:33
created

Media::getBinaryString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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