Skip to content

Commit

Permalink
Improve PR #161
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Feb 29, 2020
1 parent 3dd2732 commit 357556f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/UriTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use League\Uri\Exceptions\SyntaxError;
use League\Uri\Exceptions\TemplateCanNotBeExpanded;
use function array_filter;
use function array_key_exists;
use function array_keys;
use function explode;
use function gettype;
Expand Down Expand Up @@ -402,9 +403,7 @@ private function expandExpression(array $foundExpression): string
$parts = [];
/** @var array{name:string, modifier:string, position:string} $variable */
foreach ($expression['variables'] as $variable) {
if (isset($this->variables[$variable['name']])) {
$parts[] = $this->expandVariable($variable, $expression['operator'], $joiner, $useQuery);
}
$parts[] = $this->expandVariable($variable, $expression['operator'], $joiner, $useQuery);
}

$nullFilter = static function ($value): bool {
Expand All @@ -430,7 +429,11 @@ private function expandExpression(array $foundExpression): string
*/
private function expandVariable(array $variable, string $operator, string $joiner, bool $useQuery): string
{
$value = $this->variables[$variable['name']] ?? '';
if (!array_key_exists($variable['name'], $this->variables)) {
return '';
}

$value = $this->variables[$variable['name']];
$arguments = [$value, $variable, $operator];
$method = 'expandString';
if (is_array($value)) {
Expand Down

0 comments on commit 357556f

Please sign in to comment.