Skip to content

Commit

Permalink
Use a closure instead of static methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
fpoirotte committed Oct 1, 2014
1 parent c318405 commit ecf1059
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
37 changes: 2 additions & 35 deletions src/Interpolator/Percent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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));
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/Interpolator/PercentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit ecf1059

Please sign in to comment.