From 320b9f05741b24acbbaf1106ed267ff3817fd74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 25 Nov 2020 02:46:26 +0100 Subject: [PATCH] Clean up code a bit more --- src/Token.php | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/Token.php b/src/Token.php index faa32b5a..12613c91 100644 --- a/src/Token.php +++ b/src/Token.php @@ -32,9 +32,6 @@ */ class Token { - /** @internal */ - const FAKE_DEFAULT_VALUE = '~~~WEIRD~DEFAULT~VALUE~~~'; - /** * The token headers * @@ -160,17 +157,11 @@ public function hasHeader($name) */ public function getHeader($name, $default = null) { - if (func_num_args() === 1) { - $default = self::FAKE_DEFAULT_VALUE; - } - - $value = $this->headers->get($name, $default); - - if ($value === self::FAKE_DEFAULT_VALUE) { + if (func_num_args() === 1 && ! $this->headers->has($name)) { throw new OutOfBoundsException(sprintf('Requested header "%s" is not configured', $name)); } - return $value; + return $this->headers->get($name, $default); } /** @return DataSet */ @@ -230,16 +221,12 @@ public function hasClaim($name) */ public function getClaim($name, $default = null) { - if (func_num_args() === 1) { - $default = self::FAKE_DEFAULT_VALUE; + if (func_num_args() === 1 && ! $this->claims->has($name)) { + throw new OutOfBoundsException(sprintf('Requested header "%s" is not configured', $name)); } $value = $this->claims->get($name, $default); - if ($value === self::FAKE_DEFAULT_VALUE) { - throw new OutOfBoundsException(sprintf('Requested header "%s" is not configured', $name)); - } - if ($value instanceof DateTimeImmutable && in_array($name, RegisteredClaims::DATE_CLAIMS, true)) { return $value->getTimestamp(); }