Skip to content

Commit 1394fb5

Browse files
committed
small cleanup
1 parent a170dab commit 1394fb5

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/QueryOptions.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class QueryOptions implements RequestOptions
4747
public bool $Pretty;
4848

4949
public function __construct(
50-
array $data = [], // Deprecated do not use.
50+
null|array $data = null, // Deprecated do not use.
5151
string $Namespace = '',
5252
string $Datacenter = '',
5353
bool $AllowStale = false,
@@ -68,10 +68,6 @@ public function __construct(
6868
null|int|float|string|\DateInterval|Time\Duration $Timeout = null,
6969
bool $Pretty = false,
7070
) {
71-
if ([] !== $data) {
72-
$this->jsonUnserialize((object)$data, $this);
73-
return;
74-
}
7571
$this->Namespace = $Namespace;
7672
$this->Datacenter = $Datacenter;
7773
$this->AllowStale = $AllowStale;
@@ -91,6 +87,9 @@ public function __construct(
9187
$this->Connect = $Connect;
9288
$this->Timeout = Time::Duration($Timeout);
9389
$this->Pretty = $Pretty;
90+
if (null !== $data && [] !== $data) {
91+
$this->_fromMap((object)$data);
92+
}
9493
}
9594

9695
public function getNamespace(): string
@@ -355,27 +354,23 @@ public function apply(Request $r): void
355354
}
356355

357356
/**
358-
* @param \stdClass $decoded
359-
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $into
360-
* @return self
357+
* @param \stdClass $data
361358
* @deprecated This is only here to support construction with map. It will be removed in a future version.
362359
*/
363-
public static function jsonUnserialize(\stdClass $decoded, null|self $into = null): static
360+
private function _fromMap(\stdClass $data): void
364361
{
365-
$n = $into ?? new self();
366-
foreach ($decoded as $k => $v) {
362+
foreach ($data as $k => $v) {
367363
if ('MaxAge' === $k) {
368-
$n->MaxAge = Time::Duration($v);
364+
$this->MaxAge = Time::Duration($v);
369365
} elseif ('StaleIfError' === $k) {
370-
$n->StaleIfError = Time::Duration($v);
366+
$this->StaleIfError = Time::Duration($v);
371367
} elseif ('WaitTime' === $k) {
372-
$n->WaitTime = Time::Duration($v);
368+
$this->WaitTime = Time::Duration($v);
373369
} elseif ('Timeout' === $k) {
374-
$n->Timeout = Time::Duration($v);
370+
$this->Timeout = Time::Duration($v);
375371
} else {
376-
$n->{$k} = $v;
372+
$this->{$k} = $v;
377373
}
378374
}
379-
return $n;
380375
}
381376
}

src/ResponseValueBoolTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public function unmarshalValue(mixed $decoded): void
3636
return;
3737
}
3838
if (is_string($decoded)) {
39-
$this->Value = Transcoding::TRUE === strtolower(trim($decoded));
39+
$this->Value = 'true' === strtolower(trim($decoded));
4040
return;
4141
}
4242
$this->Value = (bool)$decoded;
4343
}
4444

4545
public function __toString(): string
4646
{
47-
return $this->Value ? Transcoding::TRUE : Transcoding::FALSE;
47+
return $this->Value ? 'true' : 'false';
4848
}
4949
}

src/Values.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function __toString(): string
120120
if ('' === $v) {
121121
$str .= $k;
122122
} else {
123-
$str .= sprintf('%s=%s', $k, $this->encode($v));
123+
$str .= "{$k}={$this->encode($v)}";
124124
}
125125
}
126126
}

0 commit comments

Comments
 (0)