Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
sten authored and github-actions[bot] committed Sep 5, 2022
1 parent 5e8686a commit 9971644
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 98 deletions.
18 changes: 9 additions & 9 deletions src/Exceptions/QuestionMapperNotImplementedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
34 changes: 17 additions & 17 deletions src/Services/Factories/QuestionMapper/AbstractQuestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
}
30 changes: 15 additions & 15 deletions src/Services/Factories/QuestionMapper/ChoiceListQuestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
52 changes: 26 additions & 26 deletions src/Services/Factories/QuestionMapper/ChoiceTableQuestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
24 changes: 12 additions & 12 deletions src/Services/Factories/QuestionMapper/InputQuestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 4 additions & 4 deletions src/Services/Factories/QuestionMapper/QuestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
30 changes: 15 additions & 15 deletions src/Services/Factories/QuestionMapper/RatingScaleQuestionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 9971644

Please sign in to comment.