Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeStatik authored and github-actions[bot] committed Aug 23, 2022
1 parent ee48ac7 commit f9c2dc6
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 3 additions & 5 deletions src/Services/Factories/AnswerCreator/AnswerCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand All @@ -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,
Expand All @@ -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 [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/Services/SurveyQuestionsAndAnswersImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Services/SurveyResponseImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -157,8 +157,6 @@ private function getQuestionResponseCreator(string $surveyheroFieldType): ?Quest
};
}



private function setResponseAsIncomplete(SurveyResponse $surveyResponse): void
{
$surveyResponse->survey_completed = false;
Expand Down

0 comments on commit f9c2dc6

Please sign in to comment.