Skip to content

Commit fe8f94b

Browse files
committed
Fixing a TODO at VBool verification.
1 parent d4720b4 commit fe8f94b

3 files changed

Lines changed: 14 additions & 24 deletions

File tree

app/V1Module/presenters/InstancesPresenter.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@
33
namespace App\V1Module\Presenters;
44

55
use App\Helpers\MetaFormats\Attributes\Post;
6-
use App\Helpers\MetaFormats\Attributes\Query;
76
use App\Helpers\MetaFormats\Attributes\Path;
8-
use App\Helpers\MetaFormats\Type;
9-
use App\Helpers\MetaFormats\Validators\VArray;
107
use App\Helpers\MetaFormats\Validators\VBool;
11-
use App\Helpers\MetaFormats\Validators\VDouble;
12-
use App\Helpers\MetaFormats\Validators\VEmail;
13-
use App\Helpers\MetaFormats\Validators\VInt;
148
use App\Helpers\MetaFormats\Validators\VMixed;
159
use App\Helpers\MetaFormats\Validators\VString;
1610
use App\Helpers\MetaFormats\Validators\VTimestamp;
17-
use App\Helpers\MetaFormats\Validators\VUuid;
1811
use App\Exceptions\ForbiddenRequestException;
1912
use App\Exceptions\NotFoundException;
2013
use App\Model\Entity\LocalizedGroup;
@@ -164,12 +157,10 @@ public function actionUpdateInstance(string $id)
164157
$instance = $this->instances->findOrThrow($id);
165158

166159
$req = $this->getRequest();
167-
$isOpen = $req->getPost("isOpen") ? filter_var(
168-
$req->getPost("isOpen"),
169-
FILTER_VALIDATE_BOOLEAN
170-
) : $instance->isOpen();
171-
172-
$instance->setIsOpen($isOpen);
160+
$isOpen = $req->getPost("isOpen");
161+
if ($isOpen !== null) {
162+
$instance->setIsOpen($isOpen);
163+
}
173164
$this->instances->persist($instance);
174165
$this->sendSuccessResponse($this->instanceViewFactory->getInstance($instance, $this->getCurrentUser()));
175166
}

app/helpers/MetaFormats/Validators/VBool.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ public function validate(mixed $value): bool
2020
return true;
2121
}
2222

23-
if ($this->strict) {
24-
///TODO: replace this with 'return false;' once the testUpdateInstance test issue is fixed.
25-
return $value === 'false';
23+
if (!$this->strict) {
24+
// FILTER_VALIDATE_BOOL is not used because it additionally allows "on", "yes", "off", "no" and ""
25+
return $value === 0
26+
|| $value === 1
27+
|| $value === "0"
28+
|| $value === "1"
29+
|| $value === "false"
30+
|| $value === "true";
2631
}
2732

28-
// FILTER_VALIDATE_BOOL is not used because it additionally allows "on", "yes", "off", "no" and ""
29-
return $value === 0
30-
|| $value === 1
31-
|| $value === "0"
32-
|| $value === "1"
33-
|| $value === "false"
34-
|| $value === "true";
33+
return false;
3534
}
3635
}

tests/Presenters/InstancesPresenter.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class TestInstancesPresenter extends Tester\TestCase
121121
'V1:Instances',
122122
'POST',
123123
['action' => 'updateInstance', 'id' => $instance->getId()],
124-
['isOpen' => 'false']
124+
['isOpen' => false]
125125
);
126126
$response = $this->presenter->run($request);
127127
Assert::type(Nette\Application\Responses\JsonResponse::class, $response);

0 commit comments

Comments
 (0)