wordpress/tests/phpunit/includes/plural-form-function.php
Tonya Mork e83a341cc0 Coding Standards: Use static closures when not using $this.
When a closure does not use `$this`, it can be made `static` for improved performance.

Static closures are supported in PHP since PHP 5.4. ​

Props jrf, hellofromTonya, swissspidy, SergeyBiryukov.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51657 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 12:57:08 +00:00

21 lines
505 B
PHP

<?php
/**
* Legacy plural form function.
*
* @param int $nplurals
* @param string $expression
*/
function tests_make_plural_form_function( $nplurals, $expression ) {
$closure = static function ( $n ) use ( $nplurals, $expression ) {
$expression = str_replace( 'n', $n, $expression );
// phpcs:ignore Squiz.PHP.Eval -- This is test code, not production.
$index = (int) eval( 'return ' . $expression . ';' );
return ( $index < $nplurals ) ? $index : $nplurals - 1;
};
return $closure;
}