Conditions | 11 |
Paths | 24 |
Total Lines | 40 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
85 | public function getUser(Request $request) |
||
86 | { |
||
87 | |||
88 | $accessToken = $request->session()->read('shopify_access_token_' . $this->api_key); |
||
89 | $shopDomain = $request->session()->read('shopify_shop_domain_' . $this->api_key); |
||
90 | |||
91 | if ($shopDomain) { |
||
92 | $this->ShopifyAPI->setShopDomain($shopDomain); |
||
93 | } |
||
94 | |||
95 | if ((isset($request->query['hmac']) && isset($request->query['shop'])) |
||
96 | && (!$shopDomain || $request->query['shop'] != $shopDomain)) { |
||
97 | $isValid = $this->ShopifyAPI->validateHMAC($request->query); |
||
98 | if ($isValid) { |
||
99 | $shopDomain = $this->ShopifyAPI->setShopDomain($request->query['shop']); |
||
100 | |||
101 | if (isset($request->query['code'])) { |
||
102 | $accessToken = $this->ShopifyAPI->getAccessToken($shopDomain, $request->query['code']); |
||
103 | } else { |
||
104 | $accessToken = $this->ShopifyDatabase->getAccessTokenFromShopDomain($shopDomain, $this->api_key); |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | |||
109 | if ($accessToken) { |
||
110 | $this->ShopifyAPI->setAccessToken($accessToken); |
||
111 | $this->ShopifyAPI->setShopDomain($shopDomain); |
||
112 | |||
113 | $request->session()->write('shopify_access_token_' . $this->api_key, $accessToken); |
||
114 | $request->session()->write('shopify_shop_domain_' . $this->api_key, $shopDomain); |
||
115 | |||
116 | $shop = $this->ShopifyDatabase->getShopDataFromAccessToken($accessToken, $this->api_key); |
||
117 | |||
118 | if ($shop && is_array($shop)) { |
||
119 | return ['id' => $shop['id'], 'username' => $shop['myshopify_domain']]; |
||
120 | } |
||
121 | } |
||
122 | |||
123 | return false; |
||
124 | } |
||
125 | |||
154 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.