/** * @param string $name * * @return RangeName * * @example * 'user{1..10}' => new RangeName('user', 1, 10) */ private function buildRange(string $name) : RangeName { $matches = []; if (false === $this->canDenormalize($name, $matches)) { throw LogicExceptionFactory::createForCannotDenormalizerForChainableFixtureBuilderDenormalizer(__METHOD__); } $reference = str_replace(sprintf('{%s}', $matches['range']), $this->token, $name); return new RangeName($reference, (int) $matches['from'], (int) $matches['to']); }
/** * @param string $id * * @return string[] * * @example * 'user_{alice, bob}' => [ * 'user_alice', * 'user_bob', * ] */ public function buildIds(string $id) : array { $matches = []; if (false === $this->canDenormalize($id, $matches)) { throw LogicExceptionFactory::createForCannotDenormalizerForChainableFixtureBuilderDenormalizer(__METHOD__); } $listElements = preg_split('/\\s*,\\s*/', $matches['list']); $ids = []; foreach ($listElements as $element) { $ids[str_replace(sprintf('{%s}', $matches['list']), $element, $id)] = $element; } return $ids; }
private function throwException(string $method) { throw LogicExceptionFactory::createForUncallableMethod($method); }