/** * @param string[] $typeSpecifiers * @param array $values * @return array * @throws InvalidTypeSpecifierException */ private function swapArguments(array $typeSpecifiers, array $values) : array { $swappedValues = []; $typeSpecifiers = array_values($typeSpecifiers); foreach ($typeSpecifiers as $key => $typeSpecifier) { $matches = []; $index = $key; if (1 === preg_match('/^%([0-9]+)\\$/', $typeSpecifier, $matches)) { if ('0' === $matches[1]) { throw InvalidTypeSpecifierException::invalidTypeSpecifier($typeSpecifier); } $index = $matches[1] - 1; } if (!array_key_exists($index, $values)) { throw InvalidTypeSpecifierException::unmatchedTypeSpecifier($typeSpecifier); } $swappedValues[] = $values[$index]; } return $swappedValues; }
/** * @expectedException \Budgegeria\IntlFormat\Exception\InvalidTypeSpecifierException * @expectedExceptionMessage The type specifier "%test" doesn't match with the given values. */ public function testUnmatchedTypeSpecifier() { throw InvalidTypeSpecifierException::unmatchedTypeSpecifier('%test'); }