AbstractBattleNet   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 54
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B _get() 0 25 5
1
<?php
2
namespace Jleagle\BattleNet\Request;
3
4
use Jleagle\BattleNet\Enums\ServerLocations;
5
use Jleagle\BattleNet\Exceptions\BattleNetException;
6
use Jleagle\CurlWrapper\Curl;
7
use Jleagle\CurlWrapper\Exceptions\CurlException;
8
9
abstract class AbstractBattleNet
10
{
11
  use BattleNetTrait;
12
13
  protected $_apiKey;
14
  protected $_responseLocale;
15
16
  /**
17
   * @param string $apiKey
18
   * @param string $serverLocation
19
   * @param string $responseLocale
20
   */
21
  public function __construct(
22
    $apiKey, $serverLocation = ServerLocations::US, $responseLocale = null
23
  )
24
  {
25
    $this->_apiKey = $apiKey;
26
    $this->_serverLocation = $serverLocation;
27
    $this->_responseLocale = $responseLocale;
28
  }
29
30
  /**
31
   * @param string $path
32
   * @param array  $data
33
   *
34
   * @return array
35
   * @throws BattleNetException
36
   */
37
  protected function _get($path, $data = [])
38
  {
39
    if($this->_responseLocale)
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_responseLocale of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
40
    {
41
      $data['locale'] = $this->_responseLocale;
42
    }
43
44
    if($this->_jsonP)
45
    {
46
      $data['jsonp'] = $this->_jsonP;
47
    }
48
49
    $data['apikey'] = $this->_apiKey;
50
51
    try
52
    {
53
      return Curl::get($this->_makeApiUrl($path), $data)->run()->getJson();
54
    }
55
    catch(CurlException $e)
56
    {
57
      $json = $e->getResponse()->getJson();
58
      $message = isset($json['reason']) ? $json['reason'] : $e->getMessage();
59
      throw new BattleNetException($message);
60
    }
61
  }
62
}
63