Completed
Pull Request — master (#6)
by AJ
12:51
created
tests/TestCase/Controller/Component/ShopifyDatabaseComponentTest.php 1 patch
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -24,8 +24,7 @@  discard block
 block discarded – undo
24 24
 use Cake\Network\Response;
25 25
 use Cake\TestSuite\TestCase;
26 26
 
27
-class ShopifyDatabaseComponentTest extends TestCase
28
-{
27
+class ShopifyDatabaseComponentTest extends TestCase {
29 28
 
30 29
     public $component = null;
31 30
     public $controller = null;
@@ -33,8 +32,7 @@  discard block
 block discarded – undo
33 32
     public $fixtures = ['plugin.Multidimensional/Shopify.Shops',
34 33
                             'plugin.Multidimensional/Shopify.AccessTokens'];
35 34
 
36
-    public function setUp()
37
-    {
35
+    public function setUp() {
38 36
         parent::setUp();
39 37
         $request = new Request();
40 38
         $response = new Response();
@@ -48,34 +46,28 @@  discard block
 block discarded – undo
48 46
         $this->component->startup($event);
49 47
     }
50 48
 
51
-    public function tearDown()
52
-    {
49
+    public function tearDown() {
53 50
         parent::tearDown();
54 51
         unset($this->component, $this->controller);
55 52
     }
56 53
 
57
-    public function testShopDataToDatabase()
58
-    {
54
+    public function testShopDataToDatabase() {
59 55
         $this->markTestIncomplete('Not implemented yet.');
60 56
     }
61 57
 
62
-    public function testAccessTokenToDatabase()
63
-    {
58
+    public function testAccessTokenToDatabase() {
64 59
         $this->markTestIncomplete('Not implemented yet.');
65 60
     }
66 61
 
67
-    public function testGetShopIdFromDomain()
68
-    {
62
+    public function testGetShopIdFromDomain() {
69 63
         $this->markTestIncomplete('Not implemented yet.');
70 64
     }
71 65
 
72
-    public function testGetShopDataFromAccessToken()
73
-    {
66
+    public function testGetShopDataFromAccessToken() {
74 67
         $this->markTestIncomplete('Not implemented yet.');
75 68
     }
76 69
 
77
-    public function testGetAccessTokenFromShopDomain()
78
-    {
70
+    public function testGetAccessTokenFromShopDomain() {
79 71
         $this->markTestIncomplete('Not implemented yet.');
80 72
     }
81 73
 }
Please login to merge, or discard this patch.
src/Auth/ShopifyAuthAuthenticate.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,17 +40,17 @@
 block discarded – undo
40 40
 		
41 41
         if (empty($this->api_key)) {
42 42
 
43
-          $controller = $this->_registry->getController();
43
+            $controller = $this->_registry->getController();
44 44
 
45
-          if (isset($controller->request->api_key)) {
45
+            if (isset($controller->request->api_key)) {
46 46
             $this->api_key = $controller->request->api_key;
47
-          }
47
+            }
48 48
 
49 49
         }
50 50
 		
51 51
         $this->ShopifyAPI = $registry->load('Multidimensional/Shopify.ShopifyAPI', [
52 52
             'api_key' => $this->api_key
53
-		]);
53
+        ]);
54 54
 
55 55
         $this->ShopifyDatabase = $registry->load('Multidimensional/Shopify.ShopifyDatabase');
56 56
     }
Please login to merge, or discard this patch.
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -25,15 +25,13 @@  discard block
 block discarded – undo
25 25
 
26 26
 use Multidimensional\Shopify\Auth\Event;
27 27
 
28
-class ShopifyAuthAuthenticate extends BaseAuthenticate
29
-{
28
+class ShopifyAuthAuthenticate extends BaseAuthenticate {
30 29
 
31 30
     public $api_key;
32 31
     private $ShopifyAPI;
33 32
     private $ShopifyDatabase;
34 33
 
35
-    public function __construct($registry, array $config = [])
36
-    {
34
+    public function __construct($registry, array $config = []) {
37 35
         parent::__construct($registry, $config);
38 36
 
39 37
         $this->api_key = isset($config['api_key']) ? $config['api_key'] : '';
@@ -55,14 +53,12 @@  discard block
 block discarded – undo
55 53
         $this->ShopifyDatabase = $registry->load('Multidimensional/Shopify.ShopifyDatabase');
56 54
     }
57 55
 
58
-    public function authenticate(Request $request, Response $response)
59
-    {
56
+    public function authenticate(Request $request, Response $response) {
60 57
 
61 58
         return $this->getUser($request);
62 59
     }
63 60
 
64
-    public function unauthenticated(Request $request, Response $response)
65
-    {
61
+    public function unauthenticated(Request $request, Response $response) {
66 62
 
67 63
         if (isset($request->query['hmac'])
68 64
             && isset($request->query['shop'])) {
@@ -84,8 +80,7 @@  discard block
 block discarded – undo
84 80
         return $response->location($this->_generateLoginUrl());
85 81
     }
86 82
 
87
-    public function getUser(Request $request)
88
-    {
83
+    public function getUser(Request $request) {
89 84
 
90 85
         $accessToken = $request->session()->read('shopify_access_token_' . $this->api_key);
91 86
         $shopDomain = $request->session()->read('shopify_shop_domain_' . $this->api_key);
@@ -125,31 +120,26 @@  discard block
 block discarded – undo
125 120
         return false;
126 121
     }
127 122
 
128
-    protected function _authenticate(Request $request)
129
-    {
123
+    protected function _authenticate(Request $request) {
130 124
     }
131 125
 
132
-    public function implementedEvents()
133
-    {
126
+    public function implementedEvents() {
134 127
         return [
135 128
             'Auth.afterIdentify' => 'afterIdentify',
136 129
             'Auth.logout' => 'logout'
137 130
         ];
138 131
     }
139 132
 
140
-    public function afterIdentify(Event $event, array $user)
141
-    {
133
+    public function afterIdentify(Event $event, array $user) {
142 134
     }
143 135
 
144
-    public function logout(Event $event, array $user)
145
-    {
136
+    public function logout(Event $event, array $user) {
146 137
 
147 138
         //$request->session()->delete('shopify_access_token_' . $this->api_key);
148 139
         //$request->session()->delete('shopify_shop_domain_' . $this->api_key);
149 140
     }
150 141
 
151
-    private function _generateLoginUrl()
152
-    {
142
+    private function _generateLoginUrl() {
153 143
         return Router::url(['controller' => 'Install', 'action' => 'index', 'plugin' => 'Multidimensional/Shopify']);
154 144
     }
155 145
 }
Please login to merge, or discard this patch.
src/Shell/Helper/TableHelper.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,11 +18,9 @@
 block discarded – undo
18 18
 use Cake\Console\Shell;
19 19
 use Cake\Console\Helper;
20 20
 
21
-class TableHelper extends Helper
22
-{
21
+class TableHelper extends Helper {
23 22
 
24
-    public function output($data, $columns = 10, $terminalWidth = 80)
25
-    {
23
+    public function output($data, $columns = 10, $terminalWidth = 80) {
26 24
         while ((count($data) % $columns != 0) && ($columns > 5)) {
27 25
             $columns--;
28 26
         }
Please login to merge, or discard this patch.
src/Shell/ShopifyInstallShell.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
         $first_run = ((Configure::check('Multidimensional/Shopify')) ? false : true);
36 36
             
37 37
         //Activate Plugin           
38
-        if ((($first_run) ? (strtolower($this->in('Install Shopify Plugin?', ['y','n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y','n'])) == 'y'))) {
38
+        if ((($first_run) ? (strtolower($this->in('Install Shopify Plugin?', ['y', 'n'])) == 'y') : (strtolower($this->in('Update Configuration?', ['y', 'n'])) == 'y'))) {
39 39
             
40 40
 
41 41
             $this->out();
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                 }
67 67
                 $scope = array_map('trim', $scope);
68 68
                 $scope = array_map('strtolower', $scope);
69
-                array_walk($scope, function (&$value) {
69
+                array_walk($scope, function(&$value) {
70 70
                     $value = str_replace(" ", "_", $value);
71 71
                 });
72 72
 
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
                     $this->_io->out('<error>Invalid Scope. Try again, or leave blank to continue.</error>');
76 76
                 }
77 77
 
78
-            } while((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scope_array)) > 0));
78
+            } while ((count($scope)) && (strlen(trim(implode("", $scope))) > 0) && (count(array_diff($scope, $scope_array)) > 0));
79 79
             
80
-            Configure::write('Multidimensional/Shopify.' . $api_key . '.scope',implode(',', $scope));
80
+            Configure::write('Multidimensional/Shopify.' . $api_key . '.scope', implode(',', $scope));
81 81
             
82 82
             $this->out('');
83 83
             $isPrivateApp = strtolower($this->in('Is this a private app?', ['y', 'n']));
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
             }
90 90
 
91 91
             
92
-            Configure::write('Multidimensional/Shopify.' . $api_key . '.is_private_app',$is_private_app);
92
+            Configure::write('Multidimensional/Shopify.' . $api_key . '.is_private_app', $is_private_app);
93 93
             
94 94
             if ($is_private_app == 'true') {
95
-                Configure::write('Multidimensional/Shopify.' . $api_key . '.private_app_password',$this->in('Private App Password:'));
95
+                Configure::write('Multidimensional/Shopify.' . $api_key . '.private_app_password', $this->in('Private App Password:'));
96 96
             } else {
97 97
                 Configure::write('Multidimensional/Shopify.' . $api_key . '.private_app_password', NULL);
98 98
             }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,11 +21,9 @@
 block discarded – undo
21 21
 use Cake\Console\Helper;
22 22
 use Migrations\Migrations;
23 23
 
24
-class ShopifyInstallShell extends Shell
25
-{
24
+class ShopifyInstallShell extends Shell {
26 25
 
27
-    public function main()
28
-    {
26
+    public function main() {
29 27
 
30 28
         $this->clear();
31 29
 
Please login to merge, or discard this patch.
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 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 
105 105
         $shopEntity = $this->shops->findByMyshopifyDomain($domain)->first();
106 106
         if ($shopEntity->id) {
107
-            return (int)$shopEntity->id;
107
+            return (int) $shopEntity->id;
108 108
         } else {
109 109
             return false;
110 110
         }
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $query = $this->access_tokens->find();
117 117
         $query = $query->contain(['Shops']);
118 118
         $query = $query->where(['api_key' => $apiKey, 'token' => $accessToken]);
119
-        $query = $query->where(function ($exp, $q) {
119
+        $query = $query->where(function($exp, $q) {
120 120
             return $exp->isNull('expired_at');
121 121
         });
122 122
 
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $query = $this->access_tokens->find();
136 136
         $query = $query->contain(['Shops']);
137 137
         $query = $query->where(['api_key' => $apiKey, 'Shops.myshopify_domain' => $shopDomain]);
138
-        $query = $query->where(function ($exp, $q) {
138
+        $query = $query->where(function($exp, $q) {
139 139
             return $exp->isNull('expired_at');
140 140
         });
141 141
 
Please login to merge, or discard this 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 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -41,26 +41,26 @@
 block discarded – undo
41 41
 
42 42
         parent::initialize($config);
43 43
         
44
-      $this->api_key = isset($config['api_key']) ? $config['api_key'] : '';
44
+        $this->api_key = isset($config['api_key']) ? $config['api_key'] : '';
45 45
 				
46
-      if (!empty($this->api_key)) {
46
+        if (!empty($this->api_key)) {
47 47
 
48 48
         $this->shared_secret = Configure::read('Multidimensional/Shopify.' . $this->api_key . '.shared_secret');
49 49
         $this->scope = Configure::read('Multidimensional/Shopify.' . $this->api_key . '.scope');
50 50
         $this->is_private_app = Configure::read('Multidimensional/Shopify.' . $this->api_key . '.is_private_app');
51 51
         $this->private_app_password = Configure::read('Multidimensional/Shopify.' . $this->api_key . '.private_app_password');        
52 52
 
53
-      } else {
53
+        } else {
54 54
 
55 55
         throw new NotImplementedException(__('Shopify API key not found'));
56 56
 
57
-      }
57
+        }
58 58
 
59
-      if (!$this->shared_secret) {
59
+        if (!$this->shared_secret) {
60 60
 
61 61
         throw new NotImplementedException(__('Shopify shared secret not found'));
62 62
 
63
-      }
63
+        }
64 64
       
65 65
     }
66 66
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@
 block discarded – undo
147 147
     {
148 148
         $params = explode("/", $this->response->getHeaderLine('http_x_shopify_shop_api_call_limit'));
149 149
 
150
-        return (int)$params[$index];
150
+        return (int) $params[$index];
151 151
     }
152 152
 
153 153
     public function getAuthorizeUrl($shopDomain, $redirectUrl)
Please login to merge, or discard this 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.