From 01b99fa92f0a05125ec0a53d62e1c6c97d76e059 Mon Sep 17 00:00:00 2001 From: sten Date: Fri, 2 Sep 2022 10:50:35 +0000 Subject: [PATCH] Fix styling --- src/Exceptions/QuestionNotMappedException.php | 18 ++--- .../ChoiceTableQuestionAndAnswerCreator.php | 70 +++++++++---------- .../InputQuestionAndAnswerCreator.php | 30 ++++---- .../QuestionResponseCreator.php | 1 - 4 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/Exceptions/QuestionNotMappedException.php b/src/Exceptions/QuestionNotMappedException.php index d3368d9..ee61721 100644 --- a/src/Exceptions/QuestionNotMappedException.php +++ b/src/Exceptions/QuestionNotMappedException.php @@ -2,15 +2,15 @@ namespace Statikbe\Surveyhero\Exceptions; - class QuestionNotMappedException extends \Exception - { - public int $questionId; +class QuestionNotMappedException extends \Exception +{ + public int $questionId; - public static function create(int $questionId, string $message): self - { - $ex = new self($message); - $ex->questionId = $questionId; + public static function create(int $questionId, string $message): self + { + $ex = new self($message); + $ex->questionId = $questionId; - return $ex; - } + return $ex; } +} diff --git a/src/Services/Factories/QuestionAndAnswerCreator/ChoiceTableQuestionAndAnswerCreator.php b/src/Services/Factories/QuestionAndAnswerCreator/ChoiceTableQuestionAndAnswerCreator.php index e6dcdfe..125ed41 100644 --- a/src/Services/Factories/QuestionAndAnswerCreator/ChoiceTableQuestionAndAnswerCreator.php +++ b/src/Services/Factories/QuestionAndAnswerCreator/ChoiceTableQuestionAndAnswerCreator.php @@ -2,44 +2,44 @@ namespace Statikbe\Surveyhero\Services\Factories\QuestionAndAnswerCreator; - use Statikbe\Surveyhero\Models\Survey; - use Statikbe\Surveyhero\Models\SurveyAnswer; - use Statikbe\Surveyhero\Models\SurveyQuestion; - use Statikbe\Surveyhero\Services\SurveyMappingService; +use Statikbe\Surveyhero\Models\Survey; +use Statikbe\Surveyhero\Models\SurveyAnswer; +use Statikbe\Surveyhero\Models\SurveyQuestion; +use Statikbe\Surveyhero\Services\SurveyMappingService; - class ChoiceTableQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator +class ChoiceTableQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator +{ + const TYPE = 'choice_table'; + + public function updateOrCreateQuestionAndAnswer(\stdClass $question, Survey $survey, string $lang): SurveyQuestion|array { - const TYPE = 'choice_table'; - - public function updateOrCreateQuestionAndAnswer(\stdClass $question, Survey $survey, string $lang): SurveyQuestion|array - { - $questions = []; - foreach ($question->question->choice_table->rows as $rowQuestion) { - $surveyQuestion = $this->updateOrCreateQuestion($survey, $lang, $question->element_id, $rowQuestion->label, $rowQuestion->row_id); - - foreach ($question->question->choice_table->choices as $choice) { - $responseData = [ - 'survey_question_id' => $surveyQuestion->id, - 'surveyhero_answer_id' => $choice->choice_id, - 'label' => [ - $lang => $choice->label, - ], - ]; - - $questionMapping = (new SurveyMappingService())->getQuestionMappingForSurvey($survey, $question->element_id); - $mappedChoice = $this->getChoiceMapping($choice->choice_id, $questionMapping); - - $this->setChoiceAndConvertToDataType($mappedChoice, $questionMapping['mapped_data_type'], $responseData, $choice); - - SurveyAnswer::updateOrCreate([ - 'survey_question_id' => $surveyQuestion->id, - 'surveyhero_answer_id' => $choice->choice_id, - ], $responseData); - } - - $questions[] = $surveyQuestion; + $questions = []; + foreach ($question->question->choice_table->rows as $rowQuestion) { + $surveyQuestion = $this->updateOrCreateQuestion($survey, $lang, $question->element_id, $rowQuestion->label, $rowQuestion->row_id); + + foreach ($question->question->choice_table->choices as $choice) { + $responseData = [ + 'survey_question_id' => $surveyQuestion->id, + 'surveyhero_answer_id' => $choice->choice_id, + 'label' => [ + $lang => $choice->label, + ], + ]; + + $questionMapping = (new SurveyMappingService())->getQuestionMappingForSurvey($survey, $question->element_id); + $mappedChoice = $this->getChoiceMapping($choice->choice_id, $questionMapping); + + $this->setChoiceAndConvertToDataType($mappedChoice, $questionMapping['mapped_data_type'], $responseData, $choice); + + SurveyAnswer::updateOrCreate([ + 'survey_question_id' => $surveyQuestion->id, + 'surveyhero_answer_id' => $choice->choice_id, + ], $responseData); } - return $questions; + $questions[] = $surveyQuestion; } + + return $questions; } +} diff --git a/src/Services/Factories/QuestionAndAnswerCreator/InputQuestionAndAnswerCreator.php b/src/Services/Factories/QuestionAndAnswerCreator/InputQuestionAndAnswerCreator.php index 2aef5bc..a53abc2 100644 --- a/src/Services/Factories/QuestionAndAnswerCreator/InputQuestionAndAnswerCreator.php +++ b/src/Services/Factories/QuestionAndAnswerCreator/InputQuestionAndAnswerCreator.php @@ -2,21 +2,21 @@ namespace Statikbe\Surveyhero\Services\Factories\QuestionAndAnswerCreator; - use Statikbe\Surveyhero\Models\Survey; - use Statikbe\Surveyhero\Models\SurveyQuestion; +use Statikbe\Surveyhero\Models\Survey; +use Statikbe\Surveyhero\Models\SurveyQuestion; - class InputQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator - { - const TYPE = 'input'; +class InputQuestionAndAnswerCreator extends AbstractQuestionAndAnswerCreator +{ + const TYPE = 'input'; - /** - * @throws \Statikbe\Surveyhero\Exceptions\SurveyNotMappedException - * @throws \Statikbe\Surveyhero\Exceptions\QuestionNotMappedException - */ - public function updateOrCreateQuestionAndAnswer(\stdClass $question, Survey $survey, string $lang): SurveyQuestion|array - { - $surveyQuestion = $this->updateOrCreateQuestion($survey, $lang, $question->element_id, $question->question->question_text); - //the answer is different for each user entry, so we cannot save answers for this type of question. - return $surveyQuestion; - } + /** + * @throws \Statikbe\Surveyhero\Exceptions\SurveyNotMappedException + * @throws \Statikbe\Surveyhero\Exceptions\QuestionNotMappedException + */ + public function updateOrCreateQuestionAndAnswer(\stdClass $question, Survey $survey, string $lang): SurveyQuestion|array + { + $surveyQuestion = $this->updateOrCreateQuestion($survey, $lang, $question->element_id, $question->question->question_text); + //the answer is different for each user entry, so we cannot save answers for this type of question. + return $surveyQuestion; } +} diff --git a/src/Services/Factories/ResponseCreator/QuestionResponseCreator.php b/src/Services/Factories/ResponseCreator/QuestionResponseCreator.php index b1cb9b4..8f05386 100644 --- a/src/Services/Factories/ResponseCreator/QuestionResponseCreator.php +++ b/src/Services/Factories/ResponseCreator/QuestionResponseCreator.php @@ -2,7 +2,6 @@ namespace Statikbe\Surveyhero\Services\Factories\ResponseCreator; -use Statikbe\Surveyhero\Exceptions\AnswerNotMappedException; use Statikbe\Surveyhero\Models\SurveyQuestionResponse; use Statikbe\Surveyhero\Models\SurveyResponse;