Skip to content

Commit

Permalink
fixed failing Lint checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza221 committed Nov 15, 2022
1 parent 542a885 commit 4c1b378
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions lib/Service/SubmissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,45 +299,44 @@ public function getQuestionCsv(int $formId, int $questionId): array {
// Process each answers
foreach ($submissionEntities as $submission) {
$currentSubmissionAnswers = $this->answerMapper->findBySubmissionAndQuestionId($submission->getId(), $questionId);
$row = [];

// User
$user = $this->userManager->get($submission->getUserId());
if ($user === null) {
// Give empty userId
$row[] = '';
// TRANSLATORS Shown on export if no Display-Name is available.
$row[] = $this->l10n->t('Anonymous user');
$row = [];

Check warning on line 302 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L300-L302

Added lines #L300 - L302 were not covered by tests

// User
$user = $this->userManager->get($submission->getUserId());
if ($user === null) {

Check warning on line 306 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L305-L306

Added lines #L305 - L306 were not covered by tests
// Give empty userId
$row[] = '';

Check warning on line 308 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L308

Added line #L308 was not covered by tests
// TRANSLATORS Shown on export if no Display-Name is available.
$row[] = $this->l10n->t('Anonymous user');
} else {
$row[] = $user->getUID();
$row[] = $user->getDisplayName();

Check warning on line 313 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L310-L313

Added lines #L310 - L313 were not covered by tests
}

// Date
$row[] = $this->dateTimeFormatter->formatDateTime($submission->getTimestamp(), 'full', 'full', new DateTimeZone($userTimezone), $this->l10n);

Check warning on line 317 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L317

Added line #L317 was not covered by tests

// Answers, make sure we keep the question order
$answers = array_reduce($currentSubmissionAnswers, function (array $carry, Answer $answer) {
$questionId = $answer->getQuestionId();

Check warning on line 321 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L320-L321

Added lines #L320 - L321 were not covered by tests

// If key exists, insert separator
if (key_exists($questionId, $carry)) {
$carry[$questionId] .= '; ' . $answer->getText();
} else {
$row[] = $user->getUID();
$row[] = $user->getDisplayName();
$carry[$questionId] = $answer->getText();

Check warning on line 327 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L324-L327

Added lines #L324 - L327 were not covered by tests
}

// Date
$row[] = $this->dateTimeFormatter->formatDateTime($submission->getTimestamp(), 'full', 'full', new DateTimeZone($userTimezone), $this->l10n);

// Answers, make sure we keep the question order
$answers = array_reduce($currentSubmissionAnswers, function (array $carry, Answer $answer) {
$questionId = $answer->getQuestionId();

// If key exists, insert separator
if (key_exists($questionId, $carry)) {
$carry[$questionId] .= '; ' . $answer->getText();
} else {
$carry[$questionId] = $answer->getText();
}

return $carry;
}, []);
return $carry;
}, []);

Check warning on line 331 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L330-L331

Added lines #L330 - L331 were not covered by tests


$row[] = key_exists($question->getId(), $answers)
$row[] = key_exists($question->getId(), $answers)
? $answers[$question->getId()]
: null;

Check warning on line 336 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L334-L336

Added lines #L334 - L336 were not covered by tests


$data[] = $row;

$data[] = $row;

Check warning on line 339 in lib/Service/SubmissionService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/SubmissionService.php#L339

Added line #L339 was not covered by tests
}

// TRANSLATORS Appendix for CSV-Export: 'Form Title (responses).csv'
Expand Down

0 comments on commit 4c1b378

Please sign in to comment.