Completed
Push — master ( ef5096...ded87a )
by Peter
02:24
created

src/Api/Betting.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace PeterColes\Betfair\Api;
4
5
use PeterColes\Betfair\Http\Client as HttpClient;
6
7
class Betting
8
{
9
    const ENDPOINT = 'https://api.betfair.com/exchange/betting/rest/v1.0/';
10
11
    protected $httpClient;
12
13
    public function __construct(HttpClient $httpClient = null)
14
    {
15
        $this->httpClient = $httpClient ?: new HttpClient;
16
    }
17
18
    public function listMarketcatalogue($filter = [ ], $marketProjection = [ ], $sort = null, $maxResults = 100, $locale = null)
19
    {
20
        return $this->httpClient
21
            ->setMethod('post')
22
            ->setEndPoint(self::ENDPOINT.'listMarketCatalogue/')
23
            ->authHeaders()
24
            ->addHeader([ 'Content-Type' => 'application/json' ])
25
            ->setFilter($filter)
26
            ->setProjection('marketProjection', $marketProjection)
27
            ->setSort($sort)
28
            ->setMaxResults($maxResults)
29
            ->setLocale($locale)
30
            ->send();
31
    }
32
33
    public function listMarketBook($marketIds = [ ], $priceProjection = null, $orderProjection = null, $matchProjection = null, $currencyCode = null, $locale = null)
34
    {
35
        return $this->httpClient
36
            ->setMethod('post')
37
            ->setEndPoint(self::ENDPOINT.'listMarketBook/')
38
            ->authHeaders()
39
            ->addHeader([ 'Content-Type' => 'application/json' ])
40
            ->setMarketIds($marketIds, true)
41
            ->setProjection('priceProjection', $priceProjection)
42
            ->setProjection('orderProjection', $orderProjection)
43
            ->setProjection('matchProjection', $matchProjection)
44
            ->setCurrencyCode($currencyCode)
45
            ->setLocale($locale)
46
            ->send();
47
    }
48
49
    public function listMarketProfitAndLoss($marketIds = [ ], $includeSettledBets = false, $includeBspBets = false, $netOfCommission = false)
50
    {
51
        return $this->httpClient
52
            ->setMethod('post')
53
            ->setEndPoint(self::ENDPOINT.'listMarketProfitAndLoss/')
54
            ->authHeaders()
55
            ->addHeader([ 'Content-Type' => 'application/json' ])
56
            ->setMarketIds($marketIds, true)
57
            ->setFlag('includeSettledBets', $includeSettledBets)
58
            ->setFlag('includeBspBets', $includeBspBets)
59
            ->setFlag('netOfCommission', $netOfCommission)
60
            ->send();
61
    }
62
63 View Code Duplication
    public function listTimeRanges($marketFilter, $timeGranularity)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        return $this->httpClient
66
            ->setMethod('post')
67
            ->setEndPoint(self::ENDPOINT.'listTimeRanges/')
68
            ->authHeaders()
69
            ->addHeader([ 'Content-Type' => 'application/json' ])
70
            ->setFilter($marketFilter)
71
            ->setTimeGranularity($timeGranularity)
72
            ->send();
73
    }
74
75
    public function listCurrentOrders($betIds = null, $marketIds = null, $orderProjection = null, $placedDateRange = null, $dateRange = null, $orderBy = null, $sortDir = null, $fromRecord = null, $recordCount = null)
76
    {
77
        return $this->httpClient
78
            ->setMethod('post')
79
            ->setEndPoint(self::ENDPOINT.'listCurrentOrders/')
80
            ->authHeaders()
81
            ->addHeader([ 'Content-Type' => 'application/json' ])
82
            ->setBetIds($betIds)
83
            ->setMarketIds($marketIds)
84
            ->setProjection('orderProjection' , $orderProjection)
85
            ->setDateRange('placedDateRange', $placedDateRange)
86
            ->setDateRange('dateRange', $dateRange)
87
            ->setOrder($orderBy, $sortDir)
88
            ->setRecordRange($fromRecord, $recordCount)
89
            ->send();
90
    }
91
92
    /**
93
     * Six Exchange methods have an identical API, so we bundle them into a single magic call e.g.
94
     * @method listCompetitions(array $filters, string $locale)
95
     * @return array
96
     */
97
    public function __call($method, $params)
98
    {
99
        if (in_array($method, [ 'listCompetitions', 'listCountries', 'listEvents', 'listEventTypes', 'listMarketTypes', 'listVenues' ])) {
100
101
            $filter = isset($params[ 0 ]) ? $params[ 0 ] : [ ];
102
            $locale = isset($params[ 1 ]) ? $params[ 1 ] : [ ];
103
104
            return $this->httpClient
105
                ->setMethod('post')
106
                ->setEndPoint(self::ENDPOINT.$method.'/')
107
                ->authHeaders()
108
                ->addHeader([ 'Content-Type' => 'application/json' ])
109
                ->setFilter($filter)
110
                ->setLocale($locale)
111
                ->send();
112
        }
113
    }
114
}
115