Created
February 13, 2009 07:57
-
-
Save juno/63783 to your computer and use it in GitHub Desktop.
Refactoring: Decompose Conditional (after)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ($this->notSummer($date)) { | |
$charge = $this->winterCharge($quantity); | |
} else { | |
$charge = $this->summerCharge($quantity); | |
} | |
... | |
/** | |
* 指定された日付が夏以外かどうかを返します。 | |
* | |
* @param object $date | |
* @return boolean | |
*/ | |
private function notSummer($date) | |
{ | |
return $date->before(SUMMER_START) || $date->after(SUMMER_END); | |
} | |
/** | |
* 夏の請求金額を返します。 | |
* | |
* @param integer $quantity 数量 | |
* @return integer | |
*/ | |
private function summerCharge($quantity) | |
{ | |
return $quantity * $this->summer_rate; | |
} | |
/** | |
* 冬の請求金額を返します。 | |
* | |
* @param integer $quantity 数量 | |
* @return integer | |
*/ | |
private function winterCharge($quantity) | |
{ | |
return $quantity * $this->winter_rate + $this->winter_service_charge; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment