/**
  * Handle the create step of object state migrations.
  *
  * @throws \Exception
  */
 protected function create()
 {
     foreach (array('object_state_group', 'names', 'identifier') as $key) {
         if (!isset($this->dsl[$key])) {
             throw new \Exception("The '{$key}' key is missing in a object state creation definition");
         }
     }
     if (!count($this->dsl['names'])) {
         throw new \Exception('No object state names have been defined. Need to specify at least one to create the state.');
     }
     $objectStateService = $this->repository->getObjectStateService();
     $objectStateGroupId = $this->dsl['object_state_group'];
     $objectStateGroupId = $this->referenceResolver->resolveReference($objectStateGroupId);
     $objectStateGroup = $this->objectStateGroupMatcher->matchOneByKey($objectStateGroupId);
     $objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct($this->dsl['identifier']);
     $objectStateCreateStruct->defaultLanguageCode = self::DEFAULT_LANGUAGE_CODE;
     foreach ($this->dsl['names'] as $languageCode => $name) {
         $objectStateCreateStruct->names[$languageCode] = $name;
     }
     if (isset($this->dsl['descriptions'])) {
         foreach ($this->dsl['descriptions'] as $languageCode => $description) {
             $objectStateCreateStruct->descriptions[$languageCode] = $description;
         }
     }
     $objectState = $objectStateService->createObjectState($objectStateGroup, $objectStateCreateStruct);
     $this->setReferences($objectState);
     return $objectState;
 }