Php cs fix

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2020-04-29 11:50:03 +02:00
parent 50d9e83ed1
commit fcae747c5f
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF
19 changed files with 67 additions and 79 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
/js/* binary

5
.gitignore vendored
View file

@ -26,4 +26,7 @@ cypress/snapshots
js/ js/
# Compile-Cache # Compile-Cache
v8-compile-cache-0/ v8-compile-cache-0/
# php-cs cache
.php_cs.cache

17
.php_cs.dist Normal file
View file

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
require_once './vendor/autoload.php';
use Nextcloud\CodingStandard\Config;
$config = new Config();
$config
->getFinder()
->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
return $config;

View file

@ -28,13 +28,9 @@ declare(strict_types=1);
namespace OCA\Forms\AppInfo; namespace OCA\Forms\AppInfo;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
class Application extends App { class Application extends App {
public const APP_ID = 'forms';
const APP_ID = 'forms';
/** /**
* Application constructor. * Application constructor.

View file

@ -47,7 +47,6 @@ use OCP\IUserSession;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
class ApiController extends Controller { class ApiController extends Controller {
protected $appName; protected $appName;
/** @var SubmissionMapper */ /** @var SubmissionMapper */
@ -123,8 +122,8 @@ class ApiController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* *
* *
* Read all information to edit a Form (form, questions, options, except submissions/answers). * Read all information to edit a Form (form, questions, options, except submissions/answers).
*/ */
public function getForm(int $id): Http\JSONResponse { public function getForm(int $id): Http\JSONResponse {
@ -307,14 +306,14 @@ class ApiController extends Controller {
} }
// Check if array contains duplicates // Check if array contains duplicates
if ( array_unique($newOrder) !== $newOrder ) { if (array_unique($newOrder) !== $newOrder) {
$this->logger->debug('The given Array contains duplicates.'); $this->logger->debug('The given Array contains duplicates.');
return new Http\JSONResponse([], Http::STATUS_BAD_REQUEST); return new Http\JSONResponse([], Http::STATUS_BAD_REQUEST);
} }
// Check if all questions are given in Array. // Check if all questions are given in Array.
$questions = $this->questionMapper->findByForm($formId); $questions = $this->questionMapper->findByForm($formId);
if ( sizeof($questions) !== sizeof($newOrder) ) { if (sizeof($questions) !== sizeof($newOrder)) {
$this->logger->debug('The length of the given array does not match the number of stored questions'); $this->logger->debug('The length of the given array does not match the number of stored questions');
return new Http\JSONResponse([], Http::STATUS_BAD_REQUEST); return new Http\JSONResponse([], Http::STATUS_BAD_REQUEST);
} }
@ -323,8 +322,7 @@ class ApiController extends Controller {
$response = []; // Array of ['questionId' => ['order' => newOrder]] $response = []; // Array of ['questionId' => ['order' => newOrder]]
// Store array of Question-Entities and check the Questions FormId & old Order. // Store array of Question-Entities and check the Questions FormId & old Order.
foreach($newOrder as $arrayKey => $questionId) { foreach ($newOrder as $arrayKey => $questionId) {
try { try {
$questions[$arrayKey] = $this->questionMapper->findById($questionId); $questions[$arrayKey] = $this->questionMapper->findById($questionId);
} catch (IMapperException $e) { } catch (IMapperException $e) {
@ -344,7 +342,7 @@ class ApiController extends Controller {
// Abort if a question is already marked as deleted (order==0) // Abort if a question is already marked as deleted (order==0)
$oldOrder = $questions[$arrayKey]->getOrder(); $oldOrder = $questions[$arrayKey]->getOrder();
if ( $oldOrder === 0) { if ($oldOrder === 0) {
$this->logger->debug('This Question has already been marked as deleted: Id: {id}', [ $this->logger->debug('This Question has already been marked as deleted: Id: {id}', [
'id' => $questions[$arrayKey]->getId() 'id' => $questions[$arrayKey]->getId()
]); ]);
@ -359,7 +357,7 @@ class ApiController extends Controller {
} }
// Write to Database // Write to Database
foreach($questions as $question) { foreach ($questions as $question) {
$this->questionMapper->update($question); $this->questionMapper->update($question);
$response[$question->getId()] = [ $response[$question->getId()] = [
@ -443,7 +441,7 @@ class ApiController extends Controller {
$formQuestions = $this->questionMapper->findByForm($form->getId()); $formQuestions = $this->questionMapper->findByForm($form->getId());
foreach ($formQuestions as $question) { foreach ($formQuestions as $question) {
$questionOrder = $question->getOrder(); $questionOrder = $question->getOrder();
if ( $questionOrder > $deletedOrder ) { if ($questionOrder > $deletedOrder) {
$question->setOrder($questionOrder - 1); $question->setOrder($questionOrder - 1);
$this->questionMapper->update($question); $this->questionMapper->update($question);
} }
@ -489,7 +487,7 @@ class ApiController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* Writes the given key-value pairs into Database. * Writes the given key-value pairs into Database.
*
* @param int $id OptionId of option to update * @param int $id OptionId of option to update
* @param array $keyValuePairs Array of key=>value pairs to update. * @param array $keyValuePairs Array of key=>value pairs to update.
*/ */
@ -589,7 +587,7 @@ class ApiController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @PublicPage * @PublicPage
* *
* Process a new submission * Process a new submission
* @param int $formId * @param int $formId
* @param array $answers [question_id => arrayOfString] * @param array $answers [question_id => arrayOfString]
@ -617,7 +615,7 @@ class ApiController extends Controller {
$submission->setTimestamp(time()); $submission->setTimestamp(time());
// If not logged in or anonymous use anonID // If not logged in or anonymous use anonID
if (!$user || $form->getIsAnonymous()){ if (!$user || $form->getIsAnonymous()) {
$anonID = "anon-user-". hash('md5', (time() + rand())); $anonID = "anon-user-". hash('md5', (time() + rand()));
$submission->setUserId($anonID); $submission->setUserId($anonID);
} else { } else {
@ -629,7 +627,7 @@ class ApiController extends Controller {
$submissionId = $submission->getId(); $submissionId = $submission->getId();
// Process Answers // Process Answers
foreach($answers as $questionId => $answerArray) { foreach ($answers as $questionId => $answerArray) {
// Search corresponding Question, skip processing if not found // Search corresponding Question, skip processing if not found
$questionIndex = array_search($questionId, array_column($questions, 'id')); $questionIndex = array_search($questionId, array_column($questions, 'id'));
if ($questionIndex === false) { if ($questionIndex === false) {
@ -638,11 +636,11 @@ class ApiController extends Controller {
$question = $questions[$questionIndex]; $question = $questions[$questionIndex];
} }
foreach($answerArray as $answer) { foreach ($answerArray as $answer) {
if($question['type'] === 'multiple' || $question['type'] === 'multiple_unique') { if ($question['type'] === 'multiple' || $question['type'] === 'multiple_unique') {
// Search corresponding option, skip processing if not found // Search corresponding option, skip processing if not found
$optionIndex = array_search($answer, array_column($question['options'], 'id')); $optionIndex = array_search($answer, array_column($question['options'], 'id'));
if($optionIndex === false) { if ($optionIndex === false) {
continue; continue;
} else { } else {
$option = $question['options'][$optionIndex]; $option = $question['options'][$optionIndex];
@ -650,7 +648,6 @@ class ApiController extends Controller {
// Load option-text // Load option-text
$answerText = $option['text']; $answerText = $option['text'];
} else { } else {
$answerText = $answer; // Not a multiple-question, answerText is given answer $answerText = $answer; // Not a multiple-question, answerText is given answer
} }

View file

@ -44,7 +44,6 @@ use OCP\IUserSession;
use OCP\Util; use OCP\Util;
class PageController extends Controller { class PageController extends Controller {
protected $appName; protected $appName;
/** @var FormMapper */ /** @var FormMapper */
@ -115,7 +114,7 @@ class PageController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired
* *
* TODO: Implement cloning * TODO: Implement cloning
* *
* @return TemplateResponse * @return TemplateResponse
@ -189,7 +188,7 @@ class PageController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
* Check if user has access to this form * Check if user has access to this form
* *
* @param Form $form * @param Form $form
* @return boolean * @return boolean
*/ */
@ -215,7 +214,7 @@ class PageController extends Controller {
// Refuse access, if SubmitOnce is set and user already has taken part. // Refuse access, if SubmitOnce is set and user already has taken part.
if ($form->getSubmitOnce()) { if ($form->getSubmitOnce()) {
$participants = $this->submissionMapper->findParticipantsByForm($form->getId()); $participants = $this->submissionMapper->findParticipantsByForm($form->getId());
foreach($participants as $participant) { foreach ($participants as $participant) {
if ($participant === $user->getUID()) { if ($participant === $user->getUID()) {
return false; return false;
} }
@ -235,7 +234,7 @@ class PageController extends Controller {
// Check if access granted by group. // Check if access granted by group.
foreach ($access['groups'] as $group) { foreach ($access['groups'] as $group) {
if( $this->groupManager->isInGroup($user->getUID(), $group) ) { if ($this->groupManager->isInGroup($user->getUID(), $group)) {
return true; return true;
} }
} }

View file

@ -29,13 +29,10 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IConfig;
use OCP\IRequest; use OCP\IRequest;
class SystemController extends Controller { class SystemController extends Controller {
public function __construct( public function __construct(
string $appName, string $appName,
IGroupManager $groupManager, IGroupManager $groupManager,
@ -52,9 +49,9 @@ class SystemController extends Controller {
* @NoAdminRequired * @NoAdminRequired
* @return DataResponse * @return DataResponse
*/ */
public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $skipGroups = array(), $skipUsers = array()) { public function getSiteUsersAndGroups($query = '', $getGroups = true, $getUsers = true, $skipGroups = [], $skipUsers = []) {
$list = array(); $list = [];
$data = array(); $data = [];
if ($getGroups) { if ($getGroups) {
$groups = $this->groupManager->search($query); $groups = $this->groupManager->search($query);
foreach ($groups as $group) { foreach ($groups as $group) {

View file

@ -59,5 +59,4 @@ class Answer extends Entity {
'text' => htmlspecialchars_decode($this->getText()), 'text' => htmlspecialchars_decode($this->getText()),
]; ];
} }
} }

View file

@ -58,8 +58,8 @@ class AnswerMapper extends QBMapper {
} }
/** /**
* @param int $submissionId * @param int $submissionId
*/ */
public function deleteBySubmission(int $submissionId): void { public function deleteBySubmission(int $submissionId): void {
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();
@ -70,5 +70,4 @@ class AnswerMapper extends QBMapper {
$qb->execute(); $qb->execute();
} }
} }

View file

@ -50,7 +50,6 @@ use OCP\AppFramework\Db\Entity;
* @method void setSubmitOnce(bool $value) * @method void setSubmitOnce(bool $value)
*/ */
class Form extends Entity { class Form extends Entity {
protected $hash; protected $hash;
protected $title; protected $title;
protected $description; protected $description;

View file

@ -33,7 +33,7 @@ class FormMapper extends QBMapper {
/** /**
* FormMapper constructor. * FormMapper constructor.
* *
* @param IDBConnection $db * @param IDBConnection $db
*/ */
public function __construct(IDBConnection $db) { public function __construct(IDBConnection $db) {
@ -102,5 +102,4 @@ class FormMapper extends QBMapper {
return $this->findEntities($qb); return $this->findEntities($qb);
} }
} }

View file

@ -26,7 +26,6 @@ declare(strict_types=1);
namespace OCA\Forms\Db; namespace OCA\Forms\Db;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper; use OCP\AppFramework\Db\QBMapper;
@ -80,5 +79,4 @@ class OptionMapper extends QBMapper {
return $this->findEntity($qb); return $this->findEntity($qb);
} }
} }

View file

@ -48,7 +48,7 @@ class Question extends Entity {
protected $mandatory; protected $mandatory;
protected $text; protected $text;
const TYPES = [ public const TYPES = [
'short', 'short',
'long', 'long',
'multiple', 'multiple',

View file

@ -30,10 +30,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper; use OCP\AppFramework\Db\QBMapper;
use OCA\Forms\Db\OptionMapper;
class QuestionMapper extends QBMapper { class QuestionMapper extends QBMapper {
private $optionMapper; private $optionMapper;
public function __construct(IDBConnection $db, OptionMapper $optionMapper) { public function __construct(IDBConnection $db, OptionMapper $optionMapper) {
@ -102,5 +99,4 @@ class QuestionMapper extends QBMapper {
return $this->findEntity($qb); return $this->findEntity($qb);
} }
} }

View file

@ -59,5 +59,4 @@ class Submission extends Entity {
'timestamp' => $this->getTimestamp(), 'timestamp' => $this->getTimestamp(),
]; ];
} }
} }

View file

@ -29,10 +29,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper; use OCP\AppFramework\Db\QBMapper;
use OCA\Forms\Db\AnswerMapper;
class SubmissionMapper extends QBMapper { class SubmissionMapper extends QBMapper {
private $answerMapper; private $answerMapper;
/** /**
@ -80,7 +77,7 @@ class SubmissionMapper extends QBMapper {
$submissionEntities = $this->findEntities($qb); $submissionEntities = $this->findEntities($qb);
// From array of submissionEntities produce array of userIds. // From array of submissionEntities produce array of userIds.
$userIds = array_map(function($submissionEntity) { $userIds = array_map(function ($submissionEntity) {
return $submissionEntity->getUserId(); return $submissionEntity->getUserId();
}, $submissionEntities); }, $submissionEntities);
@ -88,8 +85,8 @@ class SubmissionMapper extends QBMapper {
} }
/** /**
* @param int $formId * @param int $formId
*/ */
public function deleteByForm(int $formId): void { public function deleteByForm(int $formId): void {
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();

View file

@ -23,11 +23,8 @@
namespace OCA\Forms\Migration; namespace OCA\Forms\Migration;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use OCP\DB\ISchemaWrapper; use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\Migration\SimpleMigrationStep; use OCP\Migration\SimpleMigrationStep;

View file

@ -24,8 +24,6 @@
namespace OCA\Forms\Migration; namespace OCA\Forms\Migration;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use OCP\DB\ISchemaWrapper; use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
@ -214,7 +212,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
$schema = $schemaClosure(); $schema = $schemaClosure();
// if Database exists. // if Database exists.
if( $schema->hasTable('forms_events') ){ if ($schema->hasTable('forms_events')) {
$id_mapping = []; $id_mapping = [];
$id_mapping['events'] = []; // Maps oldevent-id => ['newId' => newevent-id, 'nextQuestionOrder' => integer] $id_mapping['events'] = []; // Maps oldevent-id => ['newId' => newevent-id, 'nextQuestionOrder' => integer]
$id_mapping['questions'] = []; // Maps oldquestion-id => ['newId' => newquestion-id] $id_mapping['questions'] = []; // Maps oldquestion-id => ['newId' => newquestion-id]
@ -227,7 +225,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
$qb_fetch->select('id', 'hash', 'title', 'description', 'owner', 'created', 'access', 'expire', 'is_anonymous', 'unique') $qb_fetch->select('id', 'hash', 'title', 'description', 'owner', 'created', 'access', 'expire', 'is_anonymous', 'unique')
->from('forms_events'); ->from('forms_events');
$cursor = $qb_fetch->execute(); $cursor = $qb_fetch->execute();
while( $event = $cursor->fetch() ){ while ($event = $cursor->fetch()) {
$newAccessJSON = $this->convertAccessList($event['access']); $newAccessJSON = $this->convertAccessList($event['access']);
$qb_restore->insert('forms_v2_forms') $qb_restore->insert('forms_v2_forms')
@ -257,9 +255,9 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
$qb_fetch->select('id', 'form_id', 'form_question_type', 'form_question_text') $qb_fetch->select('id', 'form_id', 'form_question_type', 'form_question_text')
->from('forms_questions'); ->from('forms_questions');
$cursor = $qb_fetch->execute(); $cursor = $qb_fetch->execute();
while( $question = $cursor->fetch() ){ while ($question = $cursor->fetch()) {
//In case the old Question would have been longer than current possible length, create a warning and shorten text to avoid Error on upgrade. //In case the old Question would have been longer than current possible length, create a warning and shorten text to avoid Error on upgrade.
if(strlen($question['form_question_text']) > 2048) { if (strlen($question['form_question_text']) > 2048) {
$output->warning("Question-text is too long for new Database: '" . $question['form_question_text'] . "'"); $output->warning("Question-text is too long for new Database: '" . $question['form_question_text'] . "'");
$question['form_question_text'] = substr($question['form_question_text'], 0, 2048); $question['form_question_text'] = substr($question['form_question_text'], 0, 2048);
} }
@ -283,9 +281,9 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
$qb_fetch->select('question_id', 'text') $qb_fetch->select('question_id', 'text')
->from('forms_answers'); ->from('forms_answers');
$cursor = $qb_fetch->execute(); $cursor = $qb_fetch->execute();
while( $answer = $cursor->fetch() ){ while ($answer = $cursor->fetch()) {
//In case the old Answer would have been longer than current possible length, create a warning and shorten text to avoid Error on upgrade. //In case the old Answer would have been longer than current possible length, create a warning and shorten text to avoid Error on upgrade.
if(strlen($answer['text']) > 1024) { if (strlen($answer['text']) > 1024) {
$output->warning("Option-text is too long for new Database: '" . $answer['text'] . "'"); $output->warning("Option-text is too long for new Database: '" . $answer['text'] . "'");
$answer['text'] = substr($answer['text'], 0, 1024); $answer['text'] = substr($answer['text'], 0, 1024);
} }
@ -307,7 +305,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
$qb_fetch->select('id') $qb_fetch->select('id')
->from('forms_events'); ->from('forms_events');
$cursor = $qb_fetch->execute(); $cursor = $qb_fetch->execute();
while( $tmp = $cursor->fetch() ){ while ($tmp = $cursor->fetch()) {
$event_structure[$tmp['id']] = $tmp; $event_structure[$tmp['id']] = $tmp;
} }
$cursor->closeCursor(); $cursor->closeCursor();
@ -319,7 +317,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
->from('forms_questions') ->from('forms_questions')
->where($qb_fetch->expr()->eq('form_id', $qb_fetch->createNamedParameter($event['id'], IQueryBuilder::PARAM_INT))); ->where($qb_fetch->expr()->eq('form_id', $qb_fetch->createNamedParameter($event['id'], IQueryBuilder::PARAM_INT)));
$cursor = $qb_fetch->execute(); $cursor = $qb_fetch->execute();
while( $tmp = $cursor->fetch() ) { while ($tmp = $cursor->fetch()) {
$event_structure[$event['id']]['questions'][] = $tmp; $event_structure[$event['id']]['questions'][] = $tmp;
} }
$cursor->closeCursor(); $cursor->closeCursor();
@ -337,9 +335,9 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
$qb_fetch->select('id', 'form_id', 'user_id', 'vote_option_id', 'vote_option_text', 'vote_answer') $qb_fetch->select('id', 'form_id', 'user_id', 'vote_option_id', 'vote_option_text', 'vote_answer')
->from('forms_votes'); ->from('forms_votes');
$cursor = $qb_fetch->execute(); $cursor = $qb_fetch->execute();
while( $vote = $cursor->fetch() ){ while ($vote = $cursor->fetch()) {
//If the form changed, if the user changed or if vote_option_id became smaller than last one, then a new submission is interpreted. //If the form changed, if the user changed or if vote_option_id became smaller than last one, then a new submission is interpreted.
if ( ($vote['form_id'] != $last_vote['form_id']) || ($vote['user_id'] != $last_vote['user_id']) || ($vote['vote_option_id'] < $last_vote['vote_option_id'])) { if (($vote['form_id'] != $last_vote['form_id']) || ($vote['user_id'] != $last_vote['user_id']) || ($vote['vote_option_id'] < $last_vote['vote_option_id'])) {
$qb_restore->insert('forms_v2_submissions') $qb_restore->insert('forms_v2_submissions')
->values([ ->values([
'form_id' => $qb_restore->createNamedParameter($id_mapping['events'][$vote['form_id']]['newId'], IQueryBuilder::PARAM_INT), 'form_id' => $qb_restore->createNamedParameter($id_mapping['events'][$vote['form_id']]['newId'], IQueryBuilder::PARAM_INT),
@ -352,7 +350,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
$last_vote = $vote; $last_vote = $vote;
//In case the old Answer would have been longer than current possible length, create a warning and shorten text to avoid Error on upgrade. //In case the old Answer would have been longer than current possible length, create a warning and shorten text to avoid Error on upgrade.
if(strlen($vote['vote_answer']) > 2048) { if (strlen($vote['vote_answer']) > 2048) {
$output->warning("Answer-text is too long for new Database: '" . $vote['vote_answer'] . "'"); $output->warning("Answer-text is too long for new Database: '" . $vote['vote_answer'] . "'");
$vote['vote_answer'] = substr($vote['vote_answer'], 0, 2048); $vote['vote_answer'] = substr($vote['vote_answer'], 0, 2048);
} }
@ -396,7 +394,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
$accessArray['groups'] = []; $accessArray['groups'] = [];
$stringExplode = explode(';', $accessString); $stringExplode = explode(';', $accessString);
foreach($stringExplode as $string) { foreach ($stringExplode as $string) {
if (strpos($string, 'user_') === 0) { if (strpos($string, 'user_') === 0) {
$accessArray['users'][] = substr($string, 5); $accessArray['users'][] = substr($string, 5);
} elseif (strpos($string, 'group_') === 0) { } elseif (strpos($string, 'group_') === 0) {

View file

@ -54,12 +54,11 @@ class FormsService {
public function getOptions(int $questionId): array { public function getOptions(int $questionId): array {
$optionList = []; $optionList = [];
try{ try {
$optionEntities = $this->optionMapper->findByQuestion($questionId); $optionEntities = $this->optionMapper->findByQuestion($questionId);
foreach ($optionEntities as $optionEntity) { foreach ($optionEntities as $optionEntity) {
$optionList[] = $optionEntity->read(); $optionList[] = $optionEntity->read();
} }
} catch (DoesNotExistException $e) { } catch (DoesNotExistException $e) {
//handle silently //handle silently
} finally { } finally {
@ -69,17 +68,16 @@ class FormsService {
public function getQuestions(int $formId): array { public function getQuestions(int $formId): array {
$questionList = []; $questionList = [];
try{ try {
$questionEntities = $this->questionMapper->findByForm($formId); $questionEntities = $this->questionMapper->findByForm($formId);
foreach ($questionEntities as $questionEntity) { foreach ($questionEntities as $questionEntity) {
$question = $questionEntity->read(); $question = $questionEntity->read();
$question['options'] = $this->getOptions($question['id']); $question['options'] = $this->getOptions($question['id']);
$questionList[] = $question; $questionList[] = $question;
} }
} catch (DoesNotExistException $e) { } catch (DoesNotExistException $e) {
//handle silently //handle silently
}finally{ } finally {
return $questionList; return $questionList;
} }
} }
@ -98,5 +96,4 @@ class FormsService {
return $result; return $result;
} }
} }