Last active
August 29, 2015 14:05
-
-
Save rarous/dc040d71e35a5a9d616b to your computer and use it in GitHub Desktop.
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
<?php namespace BodyMassIndex; | |
abstract class Thresholds { | |
const UNDERWEIGHT = 18.5; | |
const OVERWEIGHT = 25; | |
const OBESE = 30; | |
} | |
/** | |
* Calculates Body Mass Index. | |
* @param float $mass body mass [kg] | |
* @param float $height body height [m] | |
* @return float Returns calculated Body Mass Index [kg/m^2] | |
*/ | |
function calc($mass, $height) { | |
return $mass / pow($height, 2); | |
} | |
/** | |
* Gets BMI category. | |
* @param float $bmi Body Mass Index | |
* @return string Returns BMI category | |
*/ | |
function category($bmi) { | |
if ($bmi > Thresholds::OBESE) return "obese"; | |
elseif ($bmi > Thresholds::OVERWEIGHT) return "overweight"; | |
elseif ($bmi < Thresholds::UNDERWEIGHT) return "underweight"; | |
else return "normal"; | |
} |
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
<?php | |
include 'bmi.php'; | |
use BodyMassIndex as bmi; | |
$bmi = bmi\calc(48, 1.59); | |
print bmi\category($bmi) . '\n'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment