| Conditions | 2 |
| Paths | 15 |
| Total Lines | 53 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 112 | public function save( |
||
| 113 | AppUser $appUser, |
||
| 114 | ThirdPartyUser $thirdPartyUser, |
||
| 115 | CommonAccessToken $accessToken |
||
| 116 | ) { |
||
| 117 | $sql = <<<SQL |
||
| 118 | INSERT INTO `{$this->table}` |
||
| 119 | ( |
||
| 120 | `app_user_id`, |
||
| 121 | `vendor_name`, |
||
| 122 | `vendor_email`, |
||
| 123 | `vendor_access_token`, |
||
| 124 | `vendor_refresh_token`, |
||
| 125 | `vendor_data`, |
||
| 126 | `created_at` |
||
| 127 | ) |
||
| 128 | VALUES |
||
| 129 | ( |
||
| 130 | :appUserId, |
||
| 131 | :vendorName, |
||
| 132 | :vendorEmail, |
||
| 133 | :vendorToken, |
||
| 134 | :vendorRefreshToken, |
||
| 135 | :vendorData, |
||
| 136 | NOW() |
||
| 137 | ) |
||
| 138 | ON DUPLICATE KEY UPDATE |
||
| 139 | `vendor_access_token` = VALUES(`vendor_access_token`), |
||
| 140 | `vendor_refresh_token` = VALUES(`vendor_refresh_token`), |
||
| 141 | `vendor_data` = VALUES(`vendor_data`), |
||
| 142 | `updated_at` = NOW() |
||
| 143 | SQL; |
||
| 144 | try { |
||
| 145 | $vendorData = json_encode($thirdPartyUser->toArray()); |
||
| 146 | $appUserId = $appUser->id(); |
||
| 147 | $vendorName = $accessToken->vendor(); |
||
| 148 | $vendorEmail = $thirdPartyUser->email(); |
||
| 149 | $vendorToken = $accessToken->token(); |
||
| 150 | $vendorRefreshToken = $accessToken->getRefreshToken(); |
||
| 151 | |||
| 152 | $stmt = $this->dbConnection->prepare($sql); |
||
| 153 | $stmt->bindParam(':appUserId', $appUserId, PDO::PARAM_STR); |
||
| 154 | $stmt->bindParam(':vendorName', $vendorName, PDO::PARAM_STR); |
||
| 155 | $stmt->bindParam(':vendorEmail', $vendorEmail, PDO::PARAM_STR); |
||
| 156 | $stmt->bindParam(':vendorToken', $vendorToken, PDO::PARAM_STR); |
||
| 157 | $stmt->bindParam(':vendorRefreshToken', $vendorRefreshToken, PDO::PARAM_STR); |
||
| 158 | $stmt->bindParam(':vendorData', $vendorData, PDO::PARAM_STR); |
||
| 159 | $stmt->execute(); |
||
| 160 | } catch (PDOException $ex) { |
||
| 161 | throw new DataCannotBeStoredException( |
||
| 162 | sprintf("Couldn't save the third party user data. Error : %s", $ex->getMessage()), |
||
| 163 | $ex->getCode(), |
||
| 164 | $ex |
||
| 165 | ); |
||
| 185 |