Passed
Push — main ( ac53a4...aee26d )
by Pouya
06:40 queued 03:43
created

Market::Uri()   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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
4
namespace Appino\Blockchain\Classes;
5
6
7
use Appino\Blockchain\Objects\Rate;
8
use Appino\Blockchain\Objects\ReceiveResponse;
9
10
class Market{
11
12
    private $blockchain;
13
14
    public function __construct(Blockchain $blockchain){
15
        $this->blockchain = $blockchain;
16
    }
17
18
    const URL = 'https://blockchain.info/';
19
20
    private function Uri($uri){
21
        return self::URL.'/'.$uri;
22
    }
23
24
    /**
25
     * @param string $method
26
     * @param string $uri
27
     * @param array $params
28
     * @return array|string
29
     * @throws \Appino\Blockchain\Exception\HttpError
30
     */
31
    private function call($method, $uri, $params = array()){
32
        return $this->blockchain->Request($method, $this->Uri($uri), $params);
33
    }
34
35
    public function Rates(){
36
        $response = $this->call('GET','ticker');
37
        $rates = array();
38
        foreach ($response as $Currency => $params){
39
            $rates[$Currency] = new Rate($Currency, $params);
40
        }
41
        return $rates;
42
    }
43
44
    public function ToBTC($currency, $amount){
45
        $params = [
46
            'currency' => $currency,
47
            'value' => $amount
48
        ];
49
        $response = $this->call('GET','tobtc',$params);
50
        return new ReceiveResponse($response);
51
    }
52
53
    public function ToSatoshi($currency, $amount){
54
        $params = [
55
            'currency' => $currency,
56
            'value' => $amount
57
        ];
58
        return bcmul($this->call('GET','tobtc',$params),100000000);
0 ignored issues
show
Bug introduced by
$this->call('GET', 'tobtc', $params) of type array is incompatible with the type string expected by parameter $left_operand of bcmul(). ( Ignorable by Annotation )

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

58
        return bcmul(/** @scrutinizer ignore-type */ $this->call('GET','tobtc',$params),100000000);
Loading history...
59
    }
60
61
}
62