From ecf1059dbded1adb8525debbf47c13daeda81f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Poirotte?= Date: Thu, 2 Oct 2014 00:07:57 +0200 Subject: [PATCH] Use a closure instead of static methods. --- src/Interpolator/Percent.php | 37 ++----------------------- tests/unit/Interpolator/PercentTest.php | 2 -- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/Interpolator/Percent.php b/src/Interpolator/Percent.php index 286b151..476956f 100644 --- a/src/Interpolator/Percent.php +++ b/src/Interpolator/Percent.php @@ -4,39 +4,6 @@ class Percent implements \Plop\InterpolatorInterface { - /** - * Return a percent-prefixed variable. - * - * \param string $a - * Variable to work on. - * - * \retval string - * Percent-prefixed version of the variable name. - * - * @codeCoverageIgnore - */ - private static function pctPrefix($a) - { - return '%('.$a.')'; - } - - /** - * Return an incremented and percent-prefixed variable. - * - * \param int $a - * Variable to work on. - * - * \retval string - * Incremented and percent-prefixed version - * of the variable. - * - * @codeCoverageIgnore - */ - private static function increment($a) - { - return '%'.($a + 1).'$'; - } - /// \copydoc Plop::InterpolatorInterface::interpolate(). public function interpolate($msg, array $args = array()) { @@ -56,8 +23,8 @@ public function interpolate($msg, array $args = array()) // Mapping = array(name => index) $keys = array_keys($args); $mapping = array_flip($keys); - $keys = array_map(array('static', 'pctPrefix'), $keys); - $values = array_map(array('static', 'increment'), $mapping); + $keys = array_map(function ($key) { return "%($key)"; }, $keys); + $values = array_map(function ($val) { return '%'.($val + 1).'$'; }, $mapping); $mapping = array_combine($keys, $values); $msg = strtr($msg, $mapping); return vsprintf($msg, array_values($args)); diff --git a/tests/unit/Interpolator/PercentTest.php b/tests/unit/Interpolator/PercentTest.php index 9d490f4..88bfc46 100644 --- a/tests/unit/Interpolator/PercentTest.php +++ b/tests/unit/Interpolator/PercentTest.php @@ -43,8 +43,6 @@ public function testdata() /** * @dataProvider testdata * @covers \Plop\Interpolator\Percent::interpolate - * @covers \Plop\Interpolator\Percent::pctPrefix - * @covers \Plop\Interpolator\Percent::increment */ public function testInterpolation($expected, $pattern, $args) {