diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..fc43285 --- /dev/null +++ b/rector.php @@ -0,0 +1,23 @@ +paths([ + __DIR__ . '/example', + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // register a single rule + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + // define sets of rules + // $rectorConfig->sets([ + // LevelSetList::UP_TO_PHP_81 + // ]); +}; diff --git a/src/ValueObjects/Parameter.php b/src/ValueObjects/Parameter.php new file mode 100644 index 0000000..50554af --- /dev/null +++ b/src/ValueObjects/Parameter.php @@ -0,0 +1,49 @@ + $values + */ + public static function fromArray(array $values): self + { + return new self(implode(',', $values)); + } + + public static function fromObject(object $value): self + { + return new self(json_encode($value) ?: ''); + } + + public function toString(): string + { + if (is_scalar($this->value) || $this->value === null) { + return strval($this->value); + } + + if (is_object($this->value)) { + return $this->fromObject($this->value)->toString(); + } + + if (is_array($this->value)) { + return $this->fromArray($this->value)->toString(); + } + + throw new \InvalidArgumentException('Parameter value must be scalar or null'); + } +} diff --git a/src/ValueObjects/Transporter/Payload.php b/src/ValueObjects/Transporter/Payload.php index 2e95802..a8682fc 100644 --- a/src/ValueObjects/Transporter/Payload.php +++ b/src/ValueObjects/Transporter/Payload.php @@ -10,6 +10,7 @@ use Psr\Http\Message\StreamInterface; use VicidialApi\Enums\Transporter\ContentType; use VicidialApi\Enums\Transporter\Method; +use VicidialApi\ValueObjects\Parameter; use VicidialApi\ValueObjects\ResourceUri; /** @@ -146,7 +147,7 @@ public function toRequest(BaseUri $baseUri, Headers $headers, QueryParams $query if ($this->method === Method::GET && ! empty($this->parameters)) { foreach ($this->parameters as $key => $value) { - $queryParams = $queryParams->withParam($key, $value); + $queryParams = $queryParams->withParam($key, Parameter::from($value)->toString()); } }