Completed
Push — master ( f7238e...31c6cc )
by Peter
02:35
created

Betting::listMarketProfitAndLoss()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 1
eloc 11
nc 1
nop 4
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 View Code Duplication
    public function listMarketcatalogue($filter = [ ], $marketProjection = [ ], $sort = null, $maxResults = 100, $locale = null)
0 ignored issues
show
Duplication introduced by
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...
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)
41
            ->setProjection('priceProjection', $priceProjection)
42
            ->setProjection('orderProjection', $orderProjection)
43
            ->setProjection('matchProjection', $matchProjection)
44
            ->setCurrencyCode($currencyCode)
45
            ->setLocale($locale)
46
            ->send();
47
    }
48
49 View Code Duplication
    public function listMarketProfitAndLoss($marketIds = [ ], $includeSettledBets = false, $includeBspBets = false, $netOfCommission = false)
0 ignored issues
show
Duplication introduced by
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...
50
    {
51
        return $this->httpClient
52
            ->setMethod('post')
53
            ->setEndPoint(self::ENDPOINT.'listMarketProfitAndLoss/')
54
            ->authHeaders()
55
            ->addHeader([ 'Content-Type' => 'application/json' ])
56
            ->setMarketIds($marketIds)
57
            ->setFlag('includeSettledBets', $includeSettledBets)
0 ignored issues
show
Documentation introduced by
'includeSettledBets' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to Client::setFlag() has too many arguments starting with $includeSettledBets.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
58
            ->setFlag('includeBspBets', $includeBspBets)
0 ignored issues
show
Documentation introduced by
'includeBspBets' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to Client::setFlag() has too many arguments starting with $includeBspBets.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
59
            ->setFlag('netOfCommission', $netOfCommission)
0 ignored issues
show
Documentation introduced by
'netOfCommission' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to Client::setFlag() has too many arguments starting with $netOfCommission.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
            ->send();
61
    }
62
63
    public function listTimeRanges($marketFilter, $timeGranularity)
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
    /**
76
     * Six Exchange methods have an identical API, so we bundle them into a single magic call e.g.
77
     * @method listCompetitions(array $filters, string $locale)
78
     * @return array
79
     */
80
    public function __call($method, $params)
81
    {
82
        if (in_array($method, [ 'listCompetitions', 'listCountries', 'listEvents', 'listEventTypes', 'listMarketTypes', 'listVenues' ])) {
83
84
            $filter = isset($params[ 0 ]) ? $params[ 0 ] : [ ];
85
            $locale = isset($params[ 1 ]) ? $params[ 1 ] : [ ];
86
87
            return $this->httpClient
88
                ->setMethod('post')
89
                ->setEndPoint(self::ENDPOINT.$method.'/')
90
                ->authHeaders()
91
                ->addHeader([ 'Content-Type' => 'application/json' ])
92
                ->setFilter($filter)
93
                ->setLocale($locale)
94
                ->send();
95
        }
96
    }
97
}
98