juno (owner)

Revisions

  • b5155c juno Thu Feb 12 23:57:36 -0800 2009
gist: 63783 Download_button fork
public
Description:
Refactoring: Decompose Conditional (after)
Public Clone URL: git://gist.github.com/63783.git
Embed All Files: show embed
decompose_conditional_after.php #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
}