Passed
Push — master ( d0211e...76bea9 )
by Willy
02:05
created

AuctionApi::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\AuctionApi;
4
5
use Kubinashi\BattlenetApi\Model\AuthenticationModel;
6
use Kubinashi\BattlenetApi\Model\Franchises;
7
use Kubinashi\BattlenetApi\Model\RequestModel;
8
use Kubinashi\BattlenetApi\Service\RequestService;
9
10
/**
11
 * @author  Willy Reiche
12
 * @since   2017-12-09
13
 * @version 1.0
14
 */
15
class AuctionApi
16
{
17
    /**
18
     * @var AuthenticationModel
19
     */
20
    private $authenticationModel;
21
22
    /**
23
     * @var RequestService
24
     */
25
    private $requestService;
26
27
    /**
28
     * AuctionApi constructor.
29
     *
30
     * @param AuthenticationModel $authenticationModel
31
     * @param RequestService $requestService
32
     */
33
    public function __construct(
34
        AuthenticationModel $authenticationModel,
35
        RequestService $requestService
36
    ) {
37
        $this->authenticationModel = $authenticationModel;
38
        $this->requestService = $requestService;
39
    }
40
41
    /**
42
     * This API resource provides a per-realm list of recently generated auction house data dumps
43
     *
44
     * Since the returned JSON string is to huge to decode with native functions I decided to only
45
     * return the url for retrieving the JSON string
46
     *
47
     * @param int $realm
48
     *
49
     * @return string
50
     */
51
    public function getAuctionDataStatus($realm)
52
    {
53
        $responseObject = $this->prepareResponseObject($realm);
54
        $auctionUrl = $responseObject->files[0]->url;
55
56
        return $auctionUrl;
57
    }
58
59
    /**
60
     * @param string $field
61
     *
62
     * @return RequestModel
63
     */
64 View Code Duplication
    private function prepareRequestModel($field)
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...
65
    {
66
        return new RequestModel(
67
            $this->authenticationModel->getRegion(),
68
            $this->authenticationModel->getApiKey(),
69
            $this->authenticationModel->getLocale(),
70
            ['data', $field],
71
            'auction',
72
            Franchises::WORLD_OF_WARCRAFT,
73
            ''
74
        );
75
    }
76
77
    /**
78
     * @param string $field
79
     *
80
     * @return \StdClass
81
     */
82 View Code Duplication
    private function prepareResponseObject($field)
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...
83
    {
84
        $requestModel = $this->prepareRequestModel($field);
85
        $response = $this->requestService->doRequest($requestModel);
86
        $responseObject = json_decode($response);
87
88
        return $responseObject;
89
    }
90
}
91