Permalink
Browse files

將if else構成switch

  • Loading branch information...
oomusou committed Apr 5, 2016
1 parent 038eecf commit cd5306243c8416ada62beb8fc3540cf20e79d55e
Showing with 12 additions and 11 deletions.
  1. +12 −11 app/Services/ShippingService.php
@@ -14,17 +14,18 @@ class ShippingService
*/
public function calculateFee($companyName, $weight)
{
if ($companyName == 'BlackCat') {
$blackCat = new BlackCat();
return $blackCat->calculateFee($weight);
} elseif ($companyName == 'Hsinchu') {
$hsinchu = new Hsinchu();
return $hsinchu->calculateFee($weight);
} elseif ($companyName == 'PostOffice') {
$postOffice = new PostOffice();
return $postOffice->calculateFee($weight);
} else {
throw new Exception('No company exception');
switch ($companyName) {
case 'BlackCat':
$blackCat = new BlackCat();
return $blackCat->calculateFee($weight);
case 'Hsinchu':
$hsinchu = new Hsinchu();
return $hsinchu->calculateFee($weight);
case 'PostOffice':
$postOffice = new PostOffice();
return $postOffice->calculateFee($weight);
default:
throw new Exception('No company exception');
}
}
}

0 comments on commit cd53062

Please sign in to comment.