Passed
Branch main (ac09e4)
by Pouya
03:02
created

Blockchain::Receive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Appino\Blockchain\Classes;
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
use Illuminate\Contracts\Container\Container;
11
12
class Blockchain{
13
14
    protected $client;
15
    protected $params;
16
    public $HD = false;
17
    const GET = 'GET';
18
    const POST = 'POST';
19
20
    public function __construct($config){
21
        $this->client = new Client(['base_uri'=>data_get($config,'base_uri')]);
22
        $this->params['api_code'] = data_get($config,'api_code');
23
    }
24
25
    /**
26
     * Set the IoC Container.
27
     *
28
     * @param $container Container instance
29
     *
30
     * @return Blockchain
31
     */
32
    public function setContainer(Container $container): self{
33
        $this->container = $container;
0 ignored issues
show
Bug Best Practice introduced by
The property container does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
34
        return $this;
35
    }
36
37
    /**
38
     * @return Create
39
     */
40
    public function Create(){
41
        return new Create($this);
42
    }
43
44
    /**
45
     * @return Wallet
46
     */
47
    public function Wallet(){
48
        return new Wallet($this);
49
    }
50
51
    /**
52
     * @return Receive
53
     */
54
    public function Receive(){
55
        return new Receive($this);
0 ignored issues
show
Unused Code introduced by
The call to Appino\Blockchain\Classes\Receive::__construct() has too many arguments starting with $this. ( Ignorable by Annotation )

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

55
        return /** @scrutinizer ignore-call */ new Receive($this);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
56
    }
57
58
    /**
59
     * @param $base_uri string Default : http://localhost:3000
60
     */
61
62
    public function newBaseUri($base_uri){
63
        $this->client = new Client(['base_uri'=>$base_uri]);
64
    }
65
66
    /**
67
     * @param $method
68
     * @param $url
69
     * @param $params
70
     * @return array
71
     */
72
73
    public function Request($method, $url, $params){
74
        $params = array_merge($params, $this->params);
75
        $options = array(
76
            'form_params'=>$params,
77
            'headers'=>[
78
                'Content-Type'=>'application/x-www-form-urlencoded',
79
            ]
80
        );
81
        try {
82
            $response = $this->client->request($method, $url, $options);
83
            return json_decode($response->getBody()->getContents(),true);
84
        } catch (GuzzleException $e) {
85
            echo $e->getMessage();
86
        }
87
    }
88
89
}
90