Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1.  <?php
  2.  
  3. /*
  4.  * Should I be doing this?
  5.  */
  6.  
  7. class Service {
  8.  
  9.     private function connectLicenseDatabase() {
  10.         //Some lines of code to connect to the license database
  11.         return $dbh;
  12.     }
  13.  
  14.     private function getUserDetails($order_id) {
  15.         //Some lines of code to get user datails
  16.         return $user_details
  17.     }
  18.  
  19.     private function getPaidInvoiceFromOrder($order_id) {
  20.         //Some lines of code to get the invoice id
  21.         return $invoice_id
  22.     }
  23.  
  24.     public function addLicense($params = array()) {
  25.  
  26.         $userDetails = $this->getUserDetails($params['order_id']);
  27.  
  28.         $bindings = array_merge($userDetails, $params);
  29.  
  30.         $bindings['invoice_id'] = $this->getPaidInvoiceFromOrder($params['order_id']);
  31.  
  32.         $dbh = $this->connectLicenseDatabase();
  33.  
  34.         $qry = $dbh->prepare(...);
  35.  
  36.         $qry->execute($bindings);
  37.  
  38.         return $qry->fetchAll(...);
  39.     }
  40.  
  41. }
  42.  
  43. /*
  44.  * Instead of this
  45.  */
  46.  
  47. class Service {
  48.  
  49.     public function addLicense($params = array()) {
  50.         //Some lines of code to get user details
  51.         $userDetails = array(...);
  52.         //Some lines of code to get the invoice id
  53.         $invoice_id = ...;
  54.         //Some lines of code to connect to the DB
  55.         $dbh = ...;
  56.  
  57.         $bindings = array_merge($userDetails, $params);
  58.  
  59.         $qry = $dbh->prepare(...);
  60.  
  61.         $qry->execute($bindings);
  62.  
  63.         return $qry->fetchAll(...);
  64.     }
  65.  
  66. }
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement