Created
March 21, 2012 20:09
-
-
Save aileron/2152307 to your computer and use it in GitHub Desktop.
なんでオブジェクト指向の説明って、へんてなサンプルコードをむりやりクラスにするのだろう。って思って無駄にリファクタリングしてみた。
This file contains 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
<?php | |
function getLabel($opt) | |
{ | |
$colors = Array(1=> "blue", 0=> "pink" ); | |
$namings = Array( "ちゃん", "くん", "さん", "君" ); | |
extract( array_merge(Array( "name"=> "", "sex"=> 0, "suffix"=>"", "coloring"=>"","school"=>false ), $opt) ); | |
$color = $colors[ $sex ]; | |
$naming = $names[ ($sex | (($age >= 12)*2)) ]; | |
switch($age) | |
{ | |
case 6 <= $age and $age <= 11: $category = "(小)"; break; | |
case 12 <= $age and $age <= 14: $category = "(中)"; break; | |
case 14 <= $age and $age <= 17: $category = "(高)"; break; | |
case 18 <= $age and $age <= 21: $category = "(大)"; break; | |
default: $category = ""; break; | |
} | |
if($coloring) | |
{ | |
$label = "<span style='color:{$color}'>{$name}{$naming}{$category}</span>\n"; | |
} | |
else | |
{ | |
$label = "{$name}{$naming}{$category}"; | |
} | |
return $label; | |
} | |
echo getLabel(Array('name'=>'つとむ','age'=>1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment