Skip to content

Commit

Permalink
Clean up code a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
lcobucci committed Nov 25, 2020
1 parent 8747dfa commit 320b9f0
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
*/
class Token
{
/** @internal */
const FAKE_DEFAULT_VALUE = '~~~WEIRD~DEFAULT~VALUE~~~';

/**
* The token headers
*
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 320b9f0

Please sign in to comment.