Skip to content

Commit

Permalink
Refactor null checks with 'is not null' in JwtBuilder
Browse files Browse the repository at this point in the history
To better follow the naming convention and improve code readability, the null checks in JwtBuilder.cs have been updated from 'is object' to 'is not null'. The updated null checks include the variables '_algorithm', '_algFactory', '_validator', '_jsonSerializerFactory', '_urlEncoder', and '_jwt.Payload'.
  • Loading branch information
mmfazrin-phcc-gov committed Oct 30, 2023
1 parent 808fe08 commit 4d41a9d
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/JWT/Builder/JwtBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ private void TryCreateEncoder()
if (_urlEncoder is null)
throw new InvalidOperationException($"Can't instantiate {nameof(JwtEncoder)}. Call {nameof(WithUrlEncoder)}.");

if (_algorithm is object)
if (_algorithm is not null)
_encoder = new JwtEncoder(_algorithm, jsonSerializer, _urlEncoder);
else if (_algFactory is object)
else if (_algFactory is not null)
_encoder = new JwtEncoder(_algFactory, jsonSerializer, _urlEncoder);
}

Expand All @@ -364,9 +364,9 @@ private void TryCreateDecoder()
if (_urlEncoder is null)
throw new InvalidOperationException($"Can't instantiate {nameof(JwtDecoder)}. Call {nameof(WithUrlEncoder)}.");

if (_algorithm is object)
if (_algorithm is not null)
_decoder = new JwtDecoder(jsonSerializer, _validator, _urlEncoder, _algorithm);
else if (_algFactory is object)
else if (_algFactory is not null)
_decoder = new JwtDecoder(jsonSerializer, _validator, _urlEncoder, _algFactory);
else if (!_valParams.ValidateSignature)
_decoder = new JwtDecoder(jsonSerializer, _urlEncoder);
Expand All @@ -385,7 +385,7 @@ private void TryCreateDecoderForHeader()

private void TryCreateValidator()
{
if (_validator is object)
if (_validator is not null)
return;

var jsonSerializer = _jsonSerializerFactory.Create();
Expand Down Expand Up @@ -445,10 +445,10 @@ private void EnsureCanDecodeHeader()
/// Checks whether enough dependencies were supplied to encode a new token.
/// </summary>
private bool CanEncode() =>
(_algorithm is object || _algFactory is object) &&
_jsonSerializerFactory is object &&
_urlEncoder is object &&
_jwt.Payload is object;
(_algorithm is not null || _algFactory is not null) &&
_jsonSerializerFactory is not null &&
_urlEncoder is not null &&
_jwt.Payload is not null;

/// <summary>
/// Checks whether enough dependencies were supplied to decode a token.
Expand All @@ -459,7 +459,7 @@ private bool CanDecode()
return false;

if (_valParams.ValidateSignature)
return _validator is object && (_algorithm is object || _algFactory is object);
return _validator is not null && (_algorithm is not null || _algFactory is not null);

return true;
}
Expand All @@ -469,10 +469,7 @@ private bool CanDecodeHeader()
if (_urlEncoder is null)
return false;

if (_jsonSerializerFactory is null)
return false;

return true;
return _jsonSerializerFactory is not null;
}

private string GetPropName(MemberInfo prop)
Expand Down

0 comments on commit 4d41a9d

Please sign in to comment.