Passed
Push — main ( cd1286...7e00d3 )
by Pouya
02:15
created

Blockchain::Receive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Appino\Blockchain;
4
5
use Appino\Blockchain\Classes\Create;
6
use Appino\Blockchain\Classes\Receive;
7
use Appino\Blockchain\Classes\Wallet;
8
use GuzzleHttp\Client;
9
use GuzzleHttp\Exception\GuzzleException;
10
11
class Blockchain{
12
13
    protected $client;
14
    protected $params;
15
    public $HD = false;
16
    const GET = 'GET';
17
    const POST = 'POST';
18
19
    public function __construct($config){
20
        $this->client = new Client(['base_uri'=>data_get($config,'base_uri')]);
21
        $this->params['api_code'] = data_get('api_code',null);
22
    }
23
24
    /**
25
     * @return Create
26
     */
27
    public function Create(){
28
        return new Create($this);
29
    }
30
31
    /**
32
     * @return Wallet
33
     */
34
    public function Wallet(){
35
        return new Wallet($this);
36
    }
37
38
    /**
39
     * @return Receive
40
     */
41
    public function Receive(){
42
        return new Receive($this);
43
    }
44
45
    /**
46
     * @param $base_uri string Default : http://localhost:3000
47
     */
48
49
    public function newBaseUri($base_uri){
50
        $this->client = new Client(['base_uri'=>$base_uri]);
51
    }
52
53
    /**
54
     * @param $method
55
     * @param $url
56
     * @param $params
57
     * @return array
58
     */
59
60
    public function Request($method, $url, $params){
61
        $params = array_merge($this->params, $params);
62
        $options = array(
63
            'form-params'=>$params,
64
            'headers'=>[
65
                'Content-Type'=>'application/x-www-form-urlencoded',
66
            ]
67
        );
68
69
        try {
70
            return json_decode($this->client->request($method, $url, $options),true);
0 ignored issues
show
Bug introduced by
$this->client->request($method, $url, $options) of type Psr\Http\Message\ResponseInterface is incompatible with the type string expected by parameter $json of json_decode(). ( Ignorable by Annotation )

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

70
            return json_decode(/** @scrutinizer ignore-type */ $this->client->request($method, $url, $options),true);
Loading history...
71
        } catch (GuzzleException $e) {
72
            //throw $e->getMessage();
73
        }
74
    }
75
76
}
77