plural-form-function.php 498 B

1234567891011121314151617181920
  1. <?php
  2. /**
  3. * Legacy plural form function.
  4. *
  5. * @param int $nplurals
  6. * @param string $expression
  7. */
  8. function tests_make_plural_form_function( $nplurals, $expression ) {
  9. $closure = function ( $n ) use ( $nplurals, $expression ) {
  10. $expression = str_replace( 'n', $n, $expression );
  11. // phpcs:ignore Squiz.PHP.Eval -- This is test code, not production.
  12. $index = (int) eval( 'return ' . $expression . ';' );
  13. return ( $index < $nplurals ) ? $index : $nplurals - 1;
  14. };
  15. return $closure;
  16. }