diff --git a/src/Exceptions/QuestionMapperNotImplementedException.php b/src/Exceptions/QuestionMapperNotImplementedException.php index 090d093..84c7bb4 100644 --- a/src/Exceptions/QuestionMapperNotImplementedException.php +++ b/src/Exceptions/QuestionMapperNotImplementedException.php @@ -2,15 +2,15 @@ namespace Statikbe\Surveyhero\Exceptions; - class QuestionMapperNotImplementedException extends \Exception - { - public string $questionType; +class QuestionMapperNotImplementedException extends \Exception +{ + public string $questionType; - public static function create(string $questionType): self - { - $ex = new self("There is no mapper implementation for question type: $questionType"); - $ex->questionType = $questionType; + public static function create(string $questionType): self + { + $ex = new self("There is no mapper implementation for question type: $questionType"); + $ex->questionType = $questionType; - return $ex; - } + return $ex; } +} diff --git a/src/Services/Factories/QuestionMapper/AbstractQuestionMapper.php b/src/Services/Factories/QuestionMapper/AbstractQuestionMapper.php index dc13622..e6dc28c 100644 --- a/src/Services/Factories/QuestionMapper/AbstractQuestionMapper.php +++ b/src/Services/Factories/QuestionMapper/AbstractQuestionMapper.php @@ -2,22 +2,22 @@ namespace Statikbe\Surveyhero\Services\Factories\QuestionMapper; - abstract class AbstractQuestionMapper implements QuestionMapper +abstract class AbstractQuestionMapper implements QuestionMapper +{ + /** + * @param int $questionId + * @param string $questionType + * @param string $mappedDataType + * @param int|string $questionFieldSuffix + * @return array{'question_id': int, 'type': string, 'field': string, 'mapped_data_type': string } + */ + public function createQuestionMap(int $questionId, string $questionType, string $mappedDataType, int|string $questionFieldSuffix): array { - /** - * @param int $questionId - * @param string $questionType - * @param string $mappedDataType - * @param int|string $questionFieldSuffix - * @return array{'question_id': int, 'type': string, 'field': string, 'mapped_data_type': string } - */ - public function createQuestionMap(int $questionId, string $questionType, string $mappedDataType, int|string $questionFieldSuffix): array - { - return [ - 'question_id' => $questionId, - 'type' => $questionType, - 'field' => 'question_'.$questionFieldSuffix, - 'mapped_data_type' => $mappedDataType, - ]; - } + return [ + 'question_id' => $questionId, + 'type' => $questionType, + 'field' => 'question_'.$questionFieldSuffix, + 'mapped_data_type' => $mappedDataType, + ]; } +} diff --git a/src/Services/Factories/QuestionMapper/ChoiceListQuestionMapper.php b/src/Services/Factories/QuestionMapper/ChoiceListQuestionMapper.php index 02d0cf4..1ede387 100644 --- a/src/Services/Factories/QuestionMapper/ChoiceListQuestionMapper.php +++ b/src/Services/Factories/QuestionMapper/ChoiceListQuestionMapper.php @@ -2,23 +2,23 @@ namespace Statikbe\Surveyhero\Services\Factories\QuestionMapper; - use Statikbe\Surveyhero\Models\SurveyAnswer; +use Statikbe\Surveyhero\Models\SurveyAnswer; - class ChoiceListQuestionMapper extends AbstractQuestionMapper - { - const TYPE = 'choice_list'; - - public function mapQuestion(\stdClass $question, int $questionCounter): array - { - $questionData = $this->createQuestionMap($question->element_id, - $question->question->type, - SurveyAnswer::CONVERTED_TYPE_INT, - $questionCounter); +class ChoiceListQuestionMapper extends AbstractQuestionMapper +{ + const TYPE = 'choice_list'; - foreach ($question->question->choice_list->choices as $choiceKey => $choice) { - $questionData['answer_mapping'][$choice->choice_id] = $choiceKey + 1; - } + public function mapQuestion(\stdClass $question, int $questionCounter): array + { + $questionData = $this->createQuestionMap($question->element_id, + $question->question->type, + SurveyAnswer::CONVERTED_TYPE_INT, + $questionCounter); - return $questionData; + foreach ($question->question->choice_list->choices as $choiceKey => $choice) { + $questionData['answer_mapping'][$choice->choice_id] = $choiceKey + 1; } + + return $questionData; } +} diff --git a/src/Services/Factories/QuestionMapper/ChoiceTableQuestionMapper.php b/src/Services/Factories/QuestionMapper/ChoiceTableQuestionMapper.php index ca19559..fbba00f 100644 --- a/src/Services/Factories/QuestionMapper/ChoiceTableQuestionMapper.php +++ b/src/Services/Factories/QuestionMapper/ChoiceTableQuestionMapper.php @@ -2,35 +2,35 @@ namespace Statikbe\Surveyhero\Services\Factories\QuestionMapper; - use Statikbe\Surveyhero\Models\SurveyAnswer; +use Statikbe\Surveyhero\Models\SurveyAnswer; - class ChoiceTableQuestionMapper extends AbstractQuestionMapper - { - const TYPE = 'choice_table'; - - public function mapQuestion(\stdClass $question, int $questionCounter): array - { - $mappedQuestions = []; - $subquestionIndex = 1; - // make answer mapping which is the same for each question: - $answerMapping = []; - $choiceCounter = 1; - foreach ($question->question->choice_table->choices as $questionChoice) { - $answerMapping[$questionChoice->choice_id] = $choiceCounter; - $choiceCounter++; - } +class ChoiceTableQuestionMapper extends AbstractQuestionMapper +{ + const TYPE = 'choice_table'; - //create subquestions: - foreach ($question->question->choice_table->rows as $rowQuestion) { - $questionData = $this->createQuestionMap($rowQuestion->row_id, - $question->question->type, - SurveyAnswer::CONVERTED_TYPE_INT, - "{$questionCounter}_{$subquestionIndex}"); + public function mapQuestion(\stdClass $question, int $questionCounter): array + { + $mappedQuestions = []; + $subquestionIndex = 1; + // make answer mapping which is the same for each question: + $answerMapping = []; + $choiceCounter = 1; + foreach ($question->question->choice_table->choices as $questionChoice) { + $answerMapping[$questionChoice->choice_id] = $choiceCounter; + $choiceCounter++; + } - $questionData['answer_mapping'] = $answerMapping; - $mappedQuestions[] = $questionData; - } + //create subquestions: + foreach ($question->question->choice_table->rows as $rowQuestion) { + $questionData = $this->createQuestionMap($rowQuestion->row_id, + $question->question->type, + SurveyAnswer::CONVERTED_TYPE_INT, + "{$questionCounter}_{$subquestionIndex}"); - return $mappedQuestions; + $questionData['answer_mapping'] = $answerMapping; + $mappedQuestions[] = $questionData; } + + return $mappedQuestions; } +} diff --git a/src/Services/Factories/QuestionMapper/InputQuestionMapper.php b/src/Services/Factories/QuestionMapper/InputQuestionMapper.php index bf79e55..6a96532 100644 --- a/src/Services/Factories/QuestionMapper/InputQuestionMapper.php +++ b/src/Services/Factories/QuestionMapper/InputQuestionMapper.php @@ -2,19 +2,19 @@ namespace Statikbe\Surveyhero\Services\Factories\QuestionMapper; - use Statikbe\Surveyhero\Models\SurveyAnswer; +use Statikbe\Surveyhero\Models\SurveyAnswer; - class InputQuestionMapper extends AbstractQuestionMapper - { - const TYPE = 'input'; +class InputQuestionMapper extends AbstractQuestionMapper +{ + const TYPE = 'input'; - public function mapQuestion(\stdClass $question, int $questionCounter): array - { - $questionData = $this->createQuestionMap($question->element_id, - $question->question->type, - SurveyAnswer::CONVERTED_TYPE_STRING, - $questionCounter); + public function mapQuestion(\stdClass $question, int $questionCounter): array + { + $questionData = $this->createQuestionMap($question->element_id, + $question->question->type, + SurveyAnswer::CONVERTED_TYPE_STRING, + $questionCounter); - return $questionData; - } + return $questionData; } +} diff --git a/src/Services/Factories/QuestionMapper/QuestionMapper.php b/src/Services/Factories/QuestionMapper/QuestionMapper.php index b3c7eb4..579d433 100644 --- a/src/Services/Factories/QuestionMapper/QuestionMapper.php +++ b/src/Services/Factories/QuestionMapper/QuestionMapper.php @@ -2,7 +2,7 @@ namespace Statikbe\Surveyhero\Services\Factories\QuestionMapper; - interface QuestionMapper - { - public function mapQuestion(\stdClass $question, int $questionCounter): array; - } +interface QuestionMapper +{ + public function mapQuestion(\stdClass $question, int $questionCounter): array; +} diff --git a/src/Services/Factories/QuestionMapper/RatingScaleQuestionMapper.php b/src/Services/Factories/QuestionMapper/RatingScaleQuestionMapper.php index 94f0938..6cf6dfc 100644 --- a/src/Services/Factories/QuestionMapper/RatingScaleQuestionMapper.php +++ b/src/Services/Factories/QuestionMapper/RatingScaleQuestionMapper.php @@ -2,23 +2,23 @@ namespace Statikbe\Surveyhero\Services\Factories\QuestionMapper; - use Statikbe\Surveyhero\Models\SurveyAnswer; +use Statikbe\Surveyhero\Models\SurveyAnswer; - class RatingScaleQuestionMapper extends AbstractQuestionMapper - { - const TYPE = 'rating_scale'; - - public function mapQuestion(\stdClass $question, int $questionCounter): array - { - $questionData = $this->createQuestionMap($question->element_id, - $question->question->type, - SurveyAnswer::CONVERTED_TYPE_STRING, - $questionCounter); +class RatingScaleQuestionMapper extends AbstractQuestionMapper +{ + const TYPE = 'rating_scale'; - if ($question->question->rating_scale->style == 'numerical_scale') { - $questionData['mapped_data_type'] = SurveyAnswer::CONVERTED_TYPE_INT; - } + public function mapQuestion(\stdClass $question, int $questionCounter): array + { + $questionData = $this->createQuestionMap($question->element_id, + $question->question->type, + SurveyAnswer::CONVERTED_TYPE_STRING, + $questionCounter); - return $questionData; + if ($question->question->rating_scale->style == 'numerical_scale') { + $questionData['mapped_data_type'] = SurveyAnswer::CONVERTED_TYPE_INT; } + + return $questionData; } +}