Passed
Push — master ( 838416...5aae96 )
by Nicholas
02:02
created

Writer::getHandwriting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 2
b 0
f 1
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Nickcheek\Handwriting;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Psr7\Request;
7
8
class Writer extends Builder
9
{
10
    protected string $key;
11
    protected array $auth;
12
    protected string $secret;
13
    protected Client $client;
14
15
    public function __construct($key, $secret)
16
    {
17
        parent::__construct();
18
        $this->key = $key;
19
        $this->secret = $secret;
20
        $this->auth =  ['auth' => [$this->key, $this->secret]];
21
        $this->client = new Client(['base_uri' => 'https://api.handwriting.io/']);
22
    }
23
24
    public function getAllHandwriting(array $values=[]): array
0 ignored issues
show
Unused Code introduced by
The parameter $values is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    public function getAllHandwriting(/** @scrutinizer ignore-unused */ array $values=[]): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        $client = $this->client->request('GET', 'handwritings', $this->auth);
27
        return json_decode($client->getBody()->getContents());
28
    }
29
30
    public function getHandwriting(string $handwritingID): object
31
    {
32
        $client = $this->client->request('GET', 'handwritings/'.$handwritingID, $this->auth);
33
        return json_decode($client->getBody()->getContents());
34
    }
35
36
    public function renderPNGImage($build): string
37
    {
38
        $params = ['headers'=> ['Content-Type' => 'image/png']];
39
        $this->auth = array_merge($this->auth, $params);
40
        $client = $this->client->request('GET', '/render/png?'.$build, $this->auth);
41
        $png = 'data:image/png;base64,' . base64_encode($client->getBody()->getContents());
42
        return '<img src="'.$png.'">';
43
    }
44
45
    public function renderPNGString($build): string
46
    {
47
        $params = ['headers'=> ['Content-Type' => 'image/png']];
48
        $this->auth = array_merge($this->auth, $params);
49
        $client = $this->client->request('GET', '/render/png?'.$build, $this->auth);
50
        return 'data:image/png;base64,' . base64_encode($client->getBody()->getContents());
51
    }
52
53
    public function renderPDF($build,$filePath=__DIR__.'/pdf/',$fileName='test.pdf'): string
54
    {
55
        if (!file_exists($filePath)) { mkdir($filePath, 0777, true); }
56
        $params = ['headers'=> ['Content-Type' => 'application/pdf','Content-disposition'=>'inline; filename=myFile.pdf','Accept-Ranges' => 'bytes'],'sink'=> $filePath.$fileName ];
57
        $this->auth = array_merge($this->auth, $params);
58
        $this->client->request('GET', '/render/pdf?'.$build, $this->auth);
59
        return $filePath.$fileName;
60
    }
61
}
62