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

AuctionApi   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 26.32 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 20
loc 76
ccs 0
cts 32
cp 0
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getAuctionDataStatus() 0 7 1
A prepareRequestModel() 12 12 1
A prepareResponseObject() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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