Completed
Push — master ( 89952d...528cba )
by Peter
02:15
created

Betting::filter()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 16
rs 9.4285
cc 3
eloc 11
nc 2
nop 0
1
<?php
2
3
namespace PeterColes\Betfair\Api;
4
5
use PeterColes\Betfair\Api\BaseApi;
6
7
class Betting extends BaseApi
8
{
9
    /**
10
     * Betfair API endpoint for betting subsystem requests
11
     */
12
    const ENDPOINT = 'https://api.betfair.com/exchange/betting/rest/v1.0/';
13
14
    /**
15
     * Prepare parameters for API requests, ensuring the mandatory requirments are satisfied
16
     *
17
     * @param array $params
18
     */
19
    public function prepare($params)
20
    {
21
        $this->params = !empty($params) ? $params[ 0 ] : [ ];
22
23
        // force mandatory fields
24
        $this->filter();
25
        $this->maxRecords();
26
    }
27
28
    /**
29
     * Ensure that a filter parameter is passed where mandatory
30
     */
31
    protected function filter()
32
    {
33
        $lists = [
34
            'listCompetitions',
35
            'listCountries',
36
            'listEvents',
37
            'listEventTypes',
38
            'listMarketTypes',
39
            'listVenues',
40
            'listMarketCatalogue'
41
        ];
42
43
        if (in_array($this->method, $lists) && empty($this->params[ 'filter' ])) {
44
            $this->params['filter'] = new \stdClass;
45
        }
46
    }
47
48
    /**
49
     * Ensure that a maxRecord parameter is passed where mandatory
50
     */
51
    protected function maxRecords()
52
    {
53
        if ($this->method == 'listMarketCatalogue' && empty($this->params[ 'maxResults' ])) {
54
            $this->params[ 'maxResults' ] = 1000;
55
        }
56
    }
57
}
58