diff --git a/src/Symfony/Component/Translation/Range.php b/src/Symfony/Component/Translation/Interval.php similarity index 73% rename from src/Symfony/Component/Translation/Range.php rename to src/Symfony/Component/Translation/Interval.php index d16c762faa57..955439506439 100644 --- a/src/Symfony/Component/Translation/Range.php +++ b/src/Symfony/Component/Translation/Interval.php @@ -12,13 +12,13 @@ */ /** - * Range tests if a given number belongs to a given range. + * Tests if a given number belongs to a given math interval. * - * A range can represent a finite set of numbers: + * An interval can represent a finite set of numbers: * * {1,2,3,4} * - * A range can represent numbers between two numbers: + * An interval can represent numbers between two numbers: * * [1, +Inf] * ]-1,2[ @@ -27,22 +27,24 @@ * The right delimiter can be [ (exclusive) or ] (inclusive). * Beside numbers, you can use -Inf and +Inf for the infinite. * + * @see http://en.wikipedia.org/wiki/Interval_%28mathematics%29#The_ISO_notation + * * @author Fabien Potencier */ -class Range +class Interval { /** - * Tests if the given number is in the range. + * Tests if the given number is in the math interval. * - * @param integer $number A number - * @param string $range A range of numbers + * @param integer $number A number + * @param string $interval An interval */ - static public function test($number, $range) + static public function test($number, $interval) { - $range = trim($range); + $interval = trim($interval); - if (!preg_match('/^'.self::getRangeRegexp().'$/x', $range, $matches)) { - throw new \InvalidArgumentException(sprintf('"%s" is not a valid range expression.', $range)); + if (!preg_match('/^'.self::getIntervalRegexp().'$/x', $interval, $matches)) { + throw new \InvalidArgumentException(sprintf('"%s" is not a valid interval.', $interval)); } if ($matches[1]) { @@ -66,11 +68,11 @@ static public function test($number, $range) } /** - * Returns a Regexp that matches valid ranges. + * Returns a Regexp that matches valid intervals. * * @return string A Regexp (without the delimiters) */ - static public function getRangeRegexp() + static public function getIntervalRegexp() { return <<'.Range::getRangeRegexp().')\s+(?.+?)$/x', $part, $matches)) { - $explicitRules[$matches['range']] = $matches['message']; + if (preg_match('/^(?'.Interval::getIntervalRegexp().')\s+(?.+?)$/x', $part, $matches)) { + $explicitRules[$matches['interval']] = $matches['message']; } elseif (preg_match('/^\w+\: +(.+)$/', $part, $matches)) { $standardRules[] = $matches[1]; } else { @@ -36,8 +36,8 @@ public function choose($message, $number, $locale) } // try to match an explicit rule, then fallback to the standard ones - foreach ($explicitRules as $range => $m) { - if (Range::test($number, $range)) { + foreach ($explicitRules as $interval => $m) { + if (Interval::test($number, $interval)) { return $m; } } diff --git a/tests/Symfony/Tests/Component/Translation/RangeTest.php b/tests/Symfony/Tests/Component/Translation/IntervalTest.php similarity index 77% rename from tests/Symfony/Tests/Component/Translation/RangeTest.php rename to tests/Symfony/Tests/Component/Translation/IntervalTest.php index 68a57abb2d36..45c84b5c5f7c 100644 --- a/tests/Symfony/Tests/Component/Translation/RangeTest.php +++ b/tests/Symfony/Tests/Component/Translation/IntervalTest.php @@ -11,16 +11,16 @@ namespace Symfony\Tests\Component\Translation; -use Symfony\Component\Translation\Range; +use Symfony\Component\Translation\Interval; -class RangeTest extends \PHPUnit_Framework_TestCase +class IntervalTest extends \PHPUnit_Framework_TestCase { /** * @dataProvider getTests */ - public function testTest($expected, $number, $range) + public function testTest($expected, $number, $interval) { - $this->assertEquals($expected, Range::test($number, $range)); + $this->assertEquals($expected, Interval::test($number, $interval)); } /** @@ -28,7 +28,7 @@ public function testTest($expected, $number, $range) */ public function testTestException() { - Range::test(1, 'foobar'); + Interval::test(1, 'foobar'); } public function getTests()