Completed
Pull Request — master (#304)
by Jason
05:49
created

FoxyStripeClient::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 35
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 35
rs 8.8571
c 1
b 0
f 0
cc 2
eloc 18
nc 2
nop 0
1
<?php
2
3
namespace Dynamic\FoxyStripe\Model;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;
7
use Foxy\FoxyClient\FoxyClient;
8
9
class FoxyStripeClient extends \Object
10
{
11
    /**
12
     * @var
13
     */
14
    private $client;
15
16
    /**
17
     * @var
18
     */
19
    private $current_store;
20
21
    /**
22
     * FoxyStripeClient constructor.
23
     */
24
    public function __construct()
25
    {
26
        $config = array(
27
            'use_sandbox' => false
28
        );
29
30
        $site_config = \SiteConfig::current_site_config();
31
        if ($site_config) {
32
            $config['client_id'] = $site_config->client_id;
33
            $config['client_secret'] = $site_config->client_secret;
34
            $config['refresh_token'] = $site_config->refresh_token;
35
            $config['access_token'] = $site_config->access_token;
36
        }
37
38
        $guzzle_config = array(
39
            'defaults' => array(
40
                'debug' => false,
41
                'exceptions' => false
42
            )
43
        );
44
45
        /**
46
         * Set up our Guzzle Client
47
         */
48
        $guzzle = new Client($guzzle_config);
49
        CacheSubscriber::attach($guzzle);
50
51
        /**
52
         * Get our FoxyClient
53
         */
54
        $fc = new FoxyClient($guzzle, $config);
55
56
        $this->setClient($fc);
57
        $this->setCurrentStore();
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63
    public function getClient()
64
    {
65
        return $this->client;
66
    }
67
68
    /**
69
     * @param $client
70
     * @return $this
71
     */
72
    public function setClient($client)
73
    {
74
        $this->client = $client;
75
        return $this;
76
    }
77
78
    /**
79
     * @return mixed
80
     */
81
    public function getCurrentStore()
82
    {
83
        return $this->current_store;
84
    }
85
86
    /**
87
     *
88
     */
89
    public function setCurrentStore()
90
    {
91
        $client = $this->getClient();
92
        $config = \SiteConfig::current_site_config();
93
94
        $errors = array();
0 ignored issues
show
Unused Code introduced by
$errors is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
95
        $data = array(
96
            'store_domain' => $config->StoreName,
97
        );
98
99
        if ($result = $client->get()) {
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
100
            if ($reporting_uri = $client->getLink('fx:reporting')) {
101
                if ($result = $client->get($reporting_uri)) {
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
102
                    if ($store_exists_uri = $client->getLink('fx:reporting_store_domain_exists')) {
103
                        if ($result = $client->get($store_exists_uri, $data)) {
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
104
                            $store = $client->getLink('fx:store');
105
                            $this->current_store = $store;
106
                        }
107
                    }
108
                }
109
            }
110
        }
111
    }
112
113
    /**
114
     * @param array $data
115
     */
116
    public function updateStore($data = []) {
117
        $client = $this->getClient();
118
        $client->patch($this->getCurrentStore(), $data);
119
    }
120
}
121