diff --git a/src/Services/Factories/AnswerCreator/AbstractAnswerCreator.php b/src/Services/Factories/AnswerCreator/AbstractAnswerCreator.php index 0bee781..665a803 100644 --- a/src/Services/Factories/AnswerCreator/AbstractAnswerCreator.php +++ b/src/Services/Factories/AnswerCreator/AbstractAnswerCreator.php @@ -3,12 +3,6 @@ namespace Statikbe\Surveyhero\Services\Factories\AnswerCreator; use Statikbe\Surveyhero\Exceptions\AnswerNotMappedException; -use Statikbe\Surveyhero\Exceptions\QuestionNotImportedException; -use Statikbe\Surveyhero\Http\SurveyheroClient; -use Statikbe\Surveyhero\Models\SurveyQuestion; -use Statikbe\Surveyhero\Models\SurveyQuestionResponse; -use Statikbe\Surveyhero\Models\SurveyResponse; -use Statikbe\Surveyhero\Services\SurveyMappingService; abstract class AbstractAnswerCreator implements AnswerCreator { diff --git a/src/Services/Factories/AnswerCreator/AnswerCreator.php b/src/Services/Factories/AnswerCreator/AnswerCreator.php index 55db7e9..43b01e1 100644 --- a/src/Services/Factories/AnswerCreator/AnswerCreator.php +++ b/src/Services/Factories/AnswerCreator/AnswerCreator.php @@ -4,15 +4,13 @@ use Statikbe\Surveyhero\Exceptions\AnswerNotMappedException; use Statikbe\Surveyhero\Models\SurveyQuestion; -use Statikbe\Surveyhero\Models\SurveyQuestionResponse; -use Statikbe\Surveyhero\Models\SurveyResponse; interface AnswerCreator { /** - * @param \stdClass $question - * @param \Statikbe\Surveyhero\Models\SurveyQuestion $surveyQuestion - * @param \stdClass $lang + * @param \stdClass $question + * @param \Statikbe\Surveyhero\Models\SurveyQuestion $surveyQuestion + * @param \stdClass $lang * * @throws AnswerNotMappedException */ diff --git a/src/Services/Factories/AnswerCreator/ChoiceListAnswerCreator.php b/src/Services/Factories/AnswerCreator/ChoiceListAnswerCreator.php index bf02b41..6c382cc 100644 --- a/src/Services/Factories/AnswerCreator/ChoiceListAnswerCreator.php +++ b/src/Services/Factories/AnswerCreator/ChoiceListAnswerCreator.php @@ -2,12 +2,8 @@ namespace Statikbe\Surveyhero\Services\Factories\AnswerCreator; -use Statikbe\Surveyhero\Exceptions\AnswerNotImportedException; -use Statikbe\Surveyhero\Exceptions\QuestionNotImportedException; use Statikbe\Surveyhero\Models\SurveyAnswer; use Statikbe\Surveyhero\Models\SurveyQuestion; -use Statikbe\Surveyhero\Models\SurveyQuestionResponse; -use Statikbe\Surveyhero\Models\SurveyResponse; use Statikbe\Surveyhero\Services\SurveyMappingService; class ChoiceListAnswerCreator extends AbstractAnswerCreator diff --git a/src/Services/Factories/AnswerCreator/RatingScaleAnswerCreator.php b/src/Services/Factories/AnswerCreator/RatingScaleAnswerCreator.php index c0fd6d8..f809b46 100644 --- a/src/Services/Factories/AnswerCreator/RatingScaleAnswerCreator.php +++ b/src/Services/Factories/AnswerCreator/RatingScaleAnswerCreator.php @@ -2,11 +2,8 @@ namespace Statikbe\Surveyhero\Services\Factories\AnswerCreator; -use Statikbe\Surveyhero\Exceptions\AnswerNotImportedException; use Statikbe\Surveyhero\Models\SurveyAnswer; use Statikbe\Surveyhero\Models\SurveyQuestion; -use Statikbe\Surveyhero\Models\SurveyQuestionResponse; -use Statikbe\Surveyhero\Models\SurveyResponse; class RatingScaleAnswerCreator extends AbstractAnswerCreator { diff --git a/src/Services/Factories/ResponseCreator/AbstractQuestionResponseCreator.php b/src/Services/Factories/ResponseCreator/AbstractQuestionResponseCreator.php index 4a44aaa..77e128e 100644 --- a/src/Services/Factories/ResponseCreator/AbstractQuestionResponseCreator.php +++ b/src/Services/Factories/ResponseCreator/AbstractQuestionResponseCreator.php @@ -20,12 +20,12 @@ protected function findExistingQuestionResponse(string|int $surveyheroQuestionId SurveyResponse $response, string|int $surveyheroAnswerId = null): ?SurveyQuestionResponse { - $query = SurveyQuestionResponse::whereHas('surveyQuestion', function($q) use ($surveyheroQuestionId) { - $q->where('surveyhero_question_id', $surveyheroQuestionId); + $query = SurveyQuestionResponse::whereHas('surveyQuestion', function ($q) use ($surveyheroQuestionId) { + $q->where('surveyhero_question_id', $surveyheroQuestionId); })->where('survey_response_id', $response->id); if ($surveyheroAnswerId) { - $query->whereHas('surveyAnswer', function($q) use ($surveyheroAnswerId) { + $query->whereHas('surveyAnswer', function ($q) use ($surveyheroAnswerId) { $q->where('surveyhero_answer_id', $surveyheroAnswerId); }); } @@ -34,10 +34,11 @@ protected function findExistingQuestionResponse(string|int $surveyheroQuestionId } /** - * @param \stdClass $surveyheroQuestionResponse - * @param SurveyResponse $response - * @param string $field + * @param \stdClass $surveyheroQuestionResponse + * @param SurveyResponse $response + * @param string $field * @return array{ 'surveyhero_question_id': int, 'field': string, 'survey_response_id': int } + * * @throws \Statikbe\Surveyhero\Exceptions\QuestionNotImportedException */ protected function createSurveyQuestionResponseData(\stdClass $surveyheroQuestionResponse, @@ -46,8 +47,8 @@ protected function createSurveyQuestionResponseData(\stdClass $surveyheroQuestio { $surveyQuestion = SurveyQuestion::where('surveyhero_question_id', $surveyheroQuestionResponse->element_id)->first(); - if(!$surveyQuestion) { - throw QuestionNotImportedException::create($surveyheroQuestionResponse->element_id,"Make sure to import survey question with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_questions table"); + if (! $surveyQuestion) { + throw QuestionNotImportedException::create($surveyheroQuestionResponse->element_id, "Make sure to import survey question with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_questions table"); } return [ diff --git a/src/Services/Factories/ResponseCreator/ChoiceTableResponseCreator.php b/src/Services/Factories/ResponseCreator/ChoiceTableResponseCreator.php index 6bbba9f..da26343 100644 --- a/src/Services/Factories/ResponseCreator/ChoiceTableResponseCreator.php +++ b/src/Services/Factories/ResponseCreator/ChoiceTableResponseCreator.php @@ -89,8 +89,8 @@ public function updateOrCreateQuestionResponse(\stdClass $surveyheroQuestionResp $mappedChoice = $this->getChoiceMapping($surveyheroChoice->choice_id, $questionMapping); $surveyAnswer = SurveyAnswer::where('surveyhero_answer_id', $surveyheroChoice->choice_id)->first(); - if(!$surveyAnswer) { - throw AnswerNotImportedException::create($surveyheroChoice->choice_id,"Make sure to import survey answer with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_answers table"); + if (! $surveyAnswer) { + throw AnswerNotImportedException::create($surveyheroChoice->choice_id, "Make sure to import survey answer with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_answers table"); } $responseData['survey_answer_id'] = $surveyAnswer->id; diff --git a/src/Services/Factories/ResponseCreator/ChoicesResponseCreator.php b/src/Services/Factories/ResponseCreator/ChoicesResponseCreator.php index f570f11..cf1e753 100644 --- a/src/Services/Factories/ResponseCreator/ChoicesResponseCreator.php +++ b/src/Services/Factories/ResponseCreator/ChoicesResponseCreator.php @@ -56,8 +56,8 @@ public function updateOrCreateQuestionResponse( $mappedChoice = $this->getChoiceMapping($surveyheroChoice->choice_id, $questionMapping); $surveyAnswer = SurveyAnswer::where('surveyhero_answer_id', $surveyheroChoice->choice_id)->first(); - if(!$surveyAnswer) { - throw AnswerNotImportedException::create($surveyheroChoice->choice_id,"Make sure to import survey answer with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_answers table"); + if (! $surveyAnswer) { + throw AnswerNotImportedException::create($surveyheroChoice->choice_id, "Make sure to import survey answer with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_answers table"); } $responseData['survey_answer_id'] = $surveyAnswer->id; diff --git a/src/Services/Factories/ResponseCreator/NumberResponseCreator.php b/src/Services/Factories/ResponseCreator/NumberResponseCreator.php index 2ba4d6a..2f25492 100644 --- a/src/Services/Factories/ResponseCreator/NumberResponseCreator.php +++ b/src/Services/Factories/ResponseCreator/NumberResponseCreator.php @@ -33,8 +33,8 @@ public function updateOrCreateQuestionResponse(\stdClass $surveyheroQuestionResp ->where('survey_question_id', $responseData['survey_question_id']) ->first(); - if(!$surveyAnswer) { - throw AnswerNotImportedException::create(intval($surveyheroQuestionResponse->number),"Make sure to import survey answer with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_answers table"); + if (! $surveyAnswer) { + throw AnswerNotImportedException::create(intval($surveyheroQuestionResponse->number), "Make sure to import survey answer with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_answers table"); } $responseData['survey_answer_id'] = $surveyAnswer->id; diff --git a/src/Services/Factories/ResponseCreator/TextResponseCreator.php b/src/Services/Factories/ResponseCreator/TextResponseCreator.php index adc4df7..c7f762b 100644 --- a/src/Services/Factories/ResponseCreator/TextResponseCreator.php +++ b/src/Services/Factories/ResponseCreator/TextResponseCreator.php @@ -32,8 +32,8 @@ public function updateOrCreateQuestionResponse(\stdClass $surveyheroQuestionResp ->where('survey_question_id', $responseData['survey_question_id']) ->first(); - if(!$surveyAnswer) { - throw AnswerNotImportedException::create(intval($surveyheroQuestionResponse->text),"Make sure to import survey answer with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_answers table"); + if (! $surveyAnswer) { + throw AnswerNotImportedException::create(intval($surveyheroQuestionResponse->text), "Make sure to import survey answer with Surveyhero ID $surveyheroQuestionResponse->element_id in the survey_answers table"); } $responseData['survey_answer_id'] = $surveyAnswer->id; diff --git a/src/Services/SurveyQuestionsAndAnswersImportService.php b/src/Services/SurveyQuestionsAndAnswersImportService.php index 382e002..f2e74b2 100644 --- a/src/Services/SurveyQuestionsAndAnswersImportService.php +++ b/src/Services/SurveyQuestionsAndAnswersImportService.php @@ -3,7 +3,6 @@ namespace Statikbe\Surveyhero\Services; use Illuminate\Support\Facades\DB; -use Statikbe\Surveyhero\Exceptions\AnswerNotMappedException; use Statikbe\Surveyhero\Http\SurveyheroClient; use Statikbe\Surveyhero\Models\Survey; use Statikbe\Surveyhero\Models\SurveyAnswer; diff --git a/src/Services/SurveyResponseImportService.php b/src/Services/SurveyResponseImportService.php index f44e911..a886e95 100644 --- a/src/Services/SurveyResponseImportService.php +++ b/src/Services/SurveyResponseImportService.php @@ -72,7 +72,7 @@ public function importSurveyResponses(Survey $survey): array public function importSurveyResponse($responseId, Survey $survey, $surveyQuestionMapping = null): void { if (! $surveyQuestionMapping) { - $surveyQuestionMapping = $this->surveyMappingService->getSurveyQuestionMapping($survey); + $surveyQuestionMapping = $this->surveyMappingService->getSurveyQuestionMapping($survey); } //do not import already imported data. @@ -157,8 +157,6 @@ private function getQuestionResponseCreator(string $surveyheroFieldType): ?Quest }; } - - private function setResponseAsIncomplete(SurveyResponse $surveyResponse): void { $surveyResponse->survey_completed = false;