Also fixed a few minor bugs and reworked Browser class to not use the constant UNIT_TESTING so I could get the class to 100% coverage. Adds a dependency of testing_helpers which I believe is available on Travis CI by default. Up to 75% coverage, w00t w00t!
71 lines
1.4 KiB
PHP
71 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Number Utility Collection
|
|
*
|
|
* PHP version 5
|
|
*
|
|
* Licensed under The MIT License
|
|
* Redistribution of these files must retain the above copyright notice.
|
|
*
|
|
* @author Joshua Sherman <pickles@joshtronic.com>
|
|
* @copyright Copyright 2007-2014, Joshua Sherman
|
|
* @license http://www.opensource.org/licenses/mit-license.html
|
|
* @package PICKLES
|
|
* @link https://github.com/joshtronic/pickles
|
|
*/
|
|
|
|
/**
|
|
* Number Class
|
|
*
|
|
* Just a simple collection of static functions to accomplish some of the more
|
|
* redundant numeric related manipulation.
|
|
*/
|
|
class Number
|
|
{
|
|
/**
|
|
* Ordinal Indiciator
|
|
*
|
|
* Formats a number by appending an ordinal indicator.
|
|
*
|
|
* @static
|
|
* @link http://en.wikipedia.org/wiki/Ordinal_indicator
|
|
* @link http://en.wikipedia.org/wiki/English_numerals#Ordinal_numbers
|
|
* @param string $number number to format
|
|
* @param boolean $superscript include <sup> tags
|
|
* @return string formatted number
|
|
*/
|
|
public static function ordinalIndicator($number, $superscript = false)
|
|
{
|
|
if (!in_array(($number % 100), array(11, 12, 13)))
|
|
{
|
|
switch ($number % 10)
|
|
{
|
|
case 1:
|
|
$suffix = 'st';
|
|
break;
|
|
|
|
case 2:
|
|
$suffix = 'nd';
|
|
break;
|
|
|
|
case 3:
|
|
$suffix = 'rd';
|
|
break;
|
|
|
|
default:
|
|
$suffix = 'th';
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($superscript)
|
|
{
|
|
$suffix = '<sup>' . $suffix . '</sup>';
|
|
}
|
|
|
|
return $number . $suffix;
|
|
}
|
|
}
|
|
|
|
?>
|