Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move parameter typing for extraSettings #1769

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@
$question->setText($text);
$question->setDescription('');
$question->setIsRequired(false);
$question->setExtraSettings((object)[]);
$question->setExtraSettings([]);

Check warning on line 447 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L447

Added line #L447 was not covered by tests

$question = $this->questionMapper->insert($question);

Expand Down
7 changes: 1 addition & 6 deletions lib/Db/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ public function getExtraSettings(): array {
return json_decode($this->getExtraSettingsJson() ?: '{}', true); // assoc=true, => Convert to associative Array
}

/**
* @param object|array $extraSettings
*/
public function setExtraSettings($extraSettings) {
// TODO: When the php requirement is >= 8.0 change parameter typing to `object|array` to allow assoc. arrays from `Question::fromParams`

public function setExtraSettings(array $extraSettings) {
// Remove extraSettings that are not set
foreach ($extraSettings as $key => $value) {
if ($value === false) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Service/FormsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function testGetForm(array $expected) {
$question2->setText('Question 2');
$question2->setDescription('');
$question2->setName('city');
$question2->setExtraSettings((object)[]);
$question2->setExtraSettings([]);
$this->questionMapper->expects($this->once())
->method('findByForm')
->with(42)
Expand Down