Completed
Push — master ( 4c1bbd...0c1b39 )
by AJ
11:01
created
src/Controller/InstallController.php 1 patch
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,13 +22,11 @@  discard block
 block discarded – undo
22 22
 
23 23
 use Multidimensional\Shopify\Controller\AppController;
24 24
 
25
-class InstallController extends AppController
26
-{
25
+class InstallController extends AppController {
27 26
 
28 27
     private $error;
29 28
 
30
-    public function initialize()
31
-    {
29
+    public function initialize() {
32 30
 
33 31
         parent::initialize();
34 32
         $this->loadComponent('Multidimensional/Shopify.ShopifyDatabase');
@@ -96,8 +94,7 @@  discard block
 block discarded – undo
96 94
         $this->render('index');
97 95
     }
98 96
 
99
-    public function index()
100
-    {
97
+    public function index() {
101 98
 
102 99
         if (!empty($this->request->query['code']) && !$this->error) {
103 100
 
@@ -135,8 +132,7 @@  discard block
 block discarded – undo
135 132
         }
136 133
     }
137 134
 
138
-    public function redirect($url, $status = 302)
139
-    {
135
+    public function redirect($url, $status = 302) {
140 136
 
141 137
         $this->set('shopify_auth_url', $url);
142 138
         $this->render('redirect');
Please login to merge, or discard this patch.
src/Controller/Component/ShopifyDatabaseComponent.php 1 patch
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -19,35 +19,30 @@  discard block
 block discarded – undo
19 19
 use Cake\ORM\TableRegistry;
20 20
 use Cake\Event\Event;
21 21
 
22
-class ShopifyDatabaseComponent extends Component
23
-{
22
+class ShopifyDatabaseComponent extends Component {
24 23
 
25 24
     private $shops;
26 25
     private $access_tokens;
27 26
 
28 27
     public $controller = null;
29 28
 
30
-    public function initialize(array $config = [])
31
-    {
29
+    public function initialize(array $config = []) {
32 30
         $this->shops = TableRegistry::get('Multidimensional/Shopify.Shops');
33 31
         $this->access_tokens = TableRegistry::get('Multidimensional/Shopify.AccessTokens');
34 32
     }
35 33
 
36
-    public function startup(Event $event)
37
-    {
34
+    public function startup(Event $event) {
38 35
         $this->setController($event->subject());
39 36
     }
40 37
 
41
-    public function setController($controller)
42
-    {
38
+    public function setController($controller) {
43 39
         $this->controller = $controller;
44 40
         if (!isset($this->controller->paginate)) {
45 41
             $this->controller->paginate = [];
46 42
         }
47 43
     }
48 44
 
49
-    public function shopDataToDatabase(array $data)
50
-    {
45
+    public function shopDataToDatabase(array $data) {
51 46
 
52 47
         $shopEntity = $this->shops->newEntity();
53 48
 
@@ -67,8 +62,7 @@  discard block
 block discarded – undo
67 62
     }
68 63
 
69 64
 
70
-    public function accessTokenToDatabase($accessToken, $shopId, $apiKey)
71
-    {
65
+    public function accessTokenToDatabase($accessToken, $shopId, $apiKey) {
72 66
 
73 67
         $accessTokenEntity = $this->access_tokens->newEntity();
74 68
 
@@ -99,8 +93,7 @@  discard block
 block discarded – undo
99 93
         }
100 94
     }
101 95
 
102
-    public function getShopIdFromDomain($domain)
103
-    {
96
+    public function getShopIdFromDomain($domain) {
104 97
 
105 98
         $shopEntity = $this->shops->findByMyshopifyDomain($domain)->first();
106 99
         if ($shopEntity->id) {
@@ -110,8 +103,7 @@  discard block
 block discarded – undo
110 103
         }
111 104
     }
112 105
 
113
-    public function getShopDataFromAccessToken($accessToken, $apiKey)
114
-    {
106
+    public function getShopDataFromAccessToken($accessToken, $apiKey) {
115 107
 
116 108
         $query = $this->access_tokens->find();
117 109
         $query = $query->contain(['Shops']);
@@ -129,8 +121,7 @@  discard block
 block discarded – undo
129 121
         }
130 122
     }
131 123
 
132
-    public function getAccessTokenFromShopDomain($shopDomain, $apiKey)
133
-    {
124
+    public function getAccessTokenFromShopDomain($shopDomain, $apiKey) {
134 125
 
135 126
         $query = $this->access_tokens->find();
136 127
         $query = $query->contain(['Shops']);
Please login to merge, or discard this patch.
src/Controller/Component/ShopifyAPIComponent.php 1 patch
Braces   +21 added lines, -42 removed lines patch added patch discarded remove patch
@@ -22,8 +22,7 @@  discard block
 block discarded – undo
22 22
 use Cake\Event\Event;
23 23
 use Cake\Network\Exception\NotImplementedException;
24 24
 
25
-class ShopifyAPIComponent extends Component
26
-{
25
+class ShopifyAPIComponent extends Component {
27 26
   
28 27
     public $api_key;
29 28
 
@@ -36,8 +35,7 @@  discard block
 block discarded – undo
36 35
 
37 36
     public $controller = null;
38 37
 
39
-    public function initialize(array $config = [])
40
-    {
38
+    public function initialize(array $config = []) {
41 39
 
42 40
         parent::initialize($config);
43 41
         
@@ -64,13 +62,11 @@  discard block
 block discarded – undo
64 62
       
65 63
     }
66 64
 
67
-    public function startup(Event $event)
68
-    {
65
+    public function startup(Event $event) {
69 66
         $this->setController($event->subject());
70 67
     }
71 68
 
72
-    public function setController($controller)
73
-    {
69
+    public function setController($controller) {
74 70
         $this->controller = $controller;
75 71
         if (!isset($this->controller->paginate)) {
76 72
             $this->controller->paginate = [];
@@ -78,33 +74,27 @@  discard block
 block discarded – undo
78 74
 
79 75
     }
80 76
 
81
-    public function setShopDomain($shopDomain)
82
-    {
77
+    public function setShopDomain($shopDomain) {
83 78
         return $this->shop_domain = $shopDomain;
84 79
     }
85 80
 
86
-    public function getShopDomain()
87
-    {
81
+    public function getShopDomain() {
88 82
         return $this->shop_domain;
89 83
     }
90 84
 
91
-    public function setAccessToken($token)
92
-    {
85
+    public function setAccessToken($token) {
93 86
         return $this->token = $token;
94 87
     }
95 88
 
96
-    public function callsMade()
97
-    {
89
+    public function callsMade() {
98 90
         return $this->shopApiCallLimitParam(0);
99 91
     }
100 92
 
101
-    public function callLimit()
102
-    {
93
+    public function callLimit() {
103 94
         return $this->shopApiCallLimitParam(1);
104 95
     }
105 96
 
106
-    public function callsLeft($responseHeaders)
107
-    {
97
+    public function callsLeft($responseHeaders) {
108 98
         return $this->callLimit() - $this->callsMade();
109 99
     }
110 100
 
@@ -112,8 +102,7 @@  discard block
 block discarded – undo
112 102
      * @param string $method
113 103
      * @param string $path
114 104
      */
115
-    public function call($method, $path, $params = [])
116
-    {
105
+    public function call($method, $path, $params = []) {
117 106
 
118 107
         if (!$this->_isReady()) {
119 108
             return false;
@@ -143,15 +132,13 @@  discard block
 block discarded – undo
143 132
     /**
144 133
      * @param int $index
145 134
      */
146
-    private function shopApiCallLimitParam($index)
147
-    {
135
+    private function shopApiCallLimitParam($index) {
148 136
         $params = explode("/", $this->response->getHeaderLine('http_x_shopify_shop_api_call_limit'));
149 137
 
150 138
         return (int)$params[$index];
151 139
     }
152 140
 
153
-    public function getAuthorizeUrl($shopDomain, $redirectUrl)
154
-    {
141
+    public function getAuthorizeUrl($shopDomain, $redirectUrl) {
155 142
 
156 143
         $url = 'https://' . $shopDomain . '/admin/oauth/authorize?client_id=' . $this->api_key;
157 144
         $url .= '&scope=' . urlencode($this->scope);
@@ -161,8 +148,7 @@  discard block
 block discarded – undo
161 148
         return $url;
162 149
     }
163 150
 
164
-    public function getAccessToken($shopDomain, $code)
165
-    {
151
+    public function getAccessToken($shopDomain, $code) {
166 152
 
167 153
         $this->shop_domain = $shopDomain;
168 154
 
@@ -186,33 +172,28 @@  discard block
 block discarded – undo
186 172
         }
187 173
     }
188 174
 
189
-    public function setNonce($shopDomain)
190
-    {
175
+    public function setNonce($shopDomain) {
191 176
 
192 177
         return $this->nonce = md5(strtolower($shopDomain));
193 178
     }
194 179
 
195 180
 
196
-    public function getNonce()
197
-    {
181
+    public function getNonce() {
198 182
 
199 183
         return $this->nonce;
200 184
     }
201 185
 
202
-    public function validDomain($shopDomain)
203
-    {
186
+    public function validDomain($shopDomain) {
204 187
 
205 188
         return true;
206 189
     }
207 190
 
208
-    public function getShopData()
209
-    {
191
+    public function getShopData() {
210 192
 
211 193
         return $this->call('GET', '/admin/shop.json');
212 194
     }
213 195
 
214
-    public function validateHMAC($query)
215
-    {
196
+    public function validateHMAC($query) {
216 197
 
217 198
         if (!is_array($query) || empty($query['hmac']) || !is_string($query['hmac']) || (isset($query['state']) && $query['state'] != $this->getNonce($query['shop']))) {
218 199
             return false;
@@ -237,8 +218,7 @@  discard block
 block discarded – undo
237 218
     /**
238 219
      * @param string $url
239 220
      */
240
-    private function _urlEncode($url)
241
-    {
221
+    private function _urlEncode($url) {
242 222
 
243 223
         $url = str_replace('&', '%26', $url);
244 224
         $url = str_replace('%', '%25', $url);
@@ -246,8 +226,7 @@  discard block
 block discarded – undo
246 226
         return $url;
247 227
     }
248 228
 
249
-    private function _isReady()
250
-    {
229
+    private function _isReady() {
251 230
         return strlen($this->shop_domain) > 0 && strlen($this->token) > 0;
252 231
     }
253 232
 }
Please login to merge, or discard this patch.