MarketCatalogue::withMarketProjections()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the Betfair library.
4
 *
5
 * (c) Daniele D'Angeli <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Betfair\BettingApi\MarketCatalogue;
11
12
use Betfair\AbstractBetfair;
13
use Betfair\Adapter\AdapterInterface;
14
use Betfair\Client\BetfairClientInterface;
15
use Betfair\Factory\MarketFilterFactoryInterface;
16
use Betfair\Factory\ParamFactoryInterface;
17
use Betfair\Model\MarketFilter;
18
use Betfair\Model\MarketProjection;
19
20
class MarketCatalogue extends AbstractBetfair
21
{
22
    const API_METHOD_NAME = "listMarketCatalogue";
23
    const MAX_RESULT = "100";
24
25
    private $maxResults;
26
    private $marketProjections;
27
    private $marketSort;
28
    private $locale;
29
    private $marketFilter;
30
31
    /**
32
     * @param BetfairClientInterface $betfairClient
33
     * @param AdapterInterface $adapter
34
     * @param \Betfair\Factory\ParamFactoryInterface $paramFactory
35
     * @param \Betfair\Factory\MarketFilterFactoryInterface $marketFilterFactory
36
     */
37
    public function __construct(
38
        BetfairClientInterface $betfairClient,
39
        AdapterInterface $adapter,
40
        ParamFactoryInterface $paramFactory,
41
        MarketFilterFactoryInterface $marketFilterFactory
42
    ) {
43
        parent::__construct($betfairClient, $adapter, $paramFactory, $marketFilterFactory);
44
        $this->restoreDefaultsProperties();
45
    }
46
47
    public function getResults()
48
    {
49
        $param = $this->createParam($this->marketFilter)
50
            ->setMaxResults($this->maxResults)
51
            ->setLocale($this->locale)
52
            ->setMarketSort($this->marketSort)
53
            ->setMarketProjection($this->marketProjections);
54
55
        $this->restoreDefaultsProperties();
56
57
        return $this->executeCustomQuery($param);
58
    }
59
60 View Code Duplication
    public function listMarketCatalogue(array $eventTypes)
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...
61
    {
62
        $filter = $this->createMarketFilter();
63
        $filter->setEventTypeIds($eventTypes);
64
65
        $param = $this->createParam($filter);
66
67
        $param->setMaxResults(self::MAX_RESULT);
68
69
        $this->restoreDefaultsProperties();
70
71
        return $this->adapter->adaptResponse(
72
            $this->apiNgRequest(self::API_METHOD_NAME, $param)
73
        );
74
    }
75
76 View Code Duplication
    public function getMarketCatalogueFilteredByEventIds(array $eventIds)
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...
77
    {
78
        $marketFilter = $this->createMarketFilter();
79
        $marketFilter->setEventIds($eventIds);
80
81
        $param = $this->createParam($marketFilter);
82
83
        $param->setMaxResults(self::MAX_RESULT);
84
85
        $this->restoreDefaultsProperties();
86
87
        return $this->adapter->adaptResponse(
88
            $this->apiNgRequest(self::API_METHOD_NAME, $param)
89
        );
90
    }
91
92 View Code Duplication
    public function getMarketCatalogueFilteredBy(array $eventIds, array $marketTypes)
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...
93
    {
94
        $marketFilter = $this->createMarketFilter();
95
        $marketFilter->setEventIds($eventIds);
96
        $marketFilter->setMarketTypeCodes($marketTypes);
97
98
        $param = $this->createParam($marketFilter);
99
100
        $param->setMaxResults(self::MAX_RESULT);
101
102
        $this->restoreDefaultsProperties();
103
104
        return $this->adapter->adaptResponse(
105
            $this->apiNgRequest(self::API_METHOD_NAME, $param)
106
        );
107
    }
108
109
    private function restoreDefaultsProperties()
110
    {
111
        $this->marketSort = null;
112
        $this->locale = null;
113
        $this->marketProjections = MarketProjection::getAll();
114
        $this->maxResults = self::MAX_RESULT;
115
    }
116
117
    public function withMarketFilter(MarketFilter $marketFilter)
118
    {
119
        $this->marketFilter = $marketFilter;
120
        return $this;
121
    }
122
123
    public function withMarketSort($marketSort)
124
    {
125
        $this->marketSort = $marketSort;
126
        return $this;
127
    }
128
129
    public function withMarketProjections(array $marketProjections)
130
    {
131
        $this->marketProjections = $marketProjections;
132
        return $this;
133
    }
134
135
    public function withMaxResult($maxResult)
136
    {
137
        $this->maxResults = $maxResult;
138
        return $this;
139
    }
140
141
    public function withLocale($locale)
142
    {
143
        $this->locale = $locale;
144
        return $this;
145
    }
146
}
147