Skip to content

Commit

Permalink
181 nullability warnings to go
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed Mar 25, 2024
1 parent 882c998 commit cece38c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 40 deletions.
39 changes: 19 additions & 20 deletions src/Mollie.Api/Client/BaseMollieClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ protected BaseMollieClient(string apiKey, HttpClient? httpClient = null) {
throw new ArgumentNullException(nameof(apiKey), "Mollie API key cannot be empty");
}

this._jsonConverterService = new JsonConverterService();
this._createdHttpClient = httpClient == null;
this._httpClient = httpClient ?? new HttpClient();
this._apiKey = apiKey;
_jsonConverterService = new JsonConverterService();
_createdHttpClient = httpClient == null;
_httpClient = httpClient ?? new HttpClient();
_apiKey = apiKey;
}

protected BaseMollieClient(HttpClient? httpClient = null, string apiEndpoint = ApiEndPoint) {

Check warning on line 34 in src/Mollie.Api/Client/BaseMollieClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_apiKey' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
this._apiEndpoint = apiEndpoint;
this._jsonConverterService = new JsonConverterService();
this._createdHttpClient = httpClient == null;
this._httpClient = httpClient ?? new HttpClient();
_apiEndpoint = apiEndpoint;
_jsonConverterService = new JsonConverterService();
_createdHttpClient = httpClient == null;
_httpClient = httpClient ?? new HttpClient();
}

private async Task<T> SendHttpRequest<T>(HttpMethod httpMethod, string relativeUri, object? data = null) {
Expand All @@ -47,33 +47,33 @@ private async Task<T> SendHttpRequest<T>(HttpMethod httpMethod, string relativeU
}

var response = await this._httpClient.SendAsync(httpRequest).ConfigureAwait(false);
return await this.ProcessHttpResponseMessage<T>(response).ConfigureAwait(false);
return await ProcessHttpResponseMessage<T>(response).ConfigureAwait(false);

Check warning on line 50 in src/Mollie.Api/Client/BaseMollieClient.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}

protected async Task<T> GetListAsync<T>(string relativeUri, string? from, int? limit, IDictionary<string, string>? otherParameters = null) {
string url = relativeUri + this.BuildListQueryString(from, limit, otherParameters);
return await this.SendHttpRequest<T>(HttpMethod.Get, url).ConfigureAwait(false);
return await SendHttpRequest<T>(HttpMethod.Get, url).ConfigureAwait(false);
}

protected async Task<T> GetAsync<T>(string relativeUri) {
return await this.SendHttpRequest<T>(HttpMethod.Get, relativeUri).ConfigureAwait(false);
return await SendHttpRequest<T>(HttpMethod.Get, relativeUri).ConfigureAwait(false);
}

protected async Task<T> GetAsync<T>(UrlObjectLink<T> urlObject) {
this.ValidateUrlLink(urlObject);
return await this.GetAsync<T>(urlObject.Href).ConfigureAwait(false);
ValidateUrlLink(urlObject);
return await GetAsync<T>(urlObject.Href).ConfigureAwait(false);
}

protected async Task<T> PostAsync<T>(string relativeUri, object? data) {
return await this.SendHttpRequest<T>(HttpMethod.Post, relativeUri, data).ConfigureAwait(false);
return await SendHttpRequest<T>(HttpMethod.Post, relativeUri, data).ConfigureAwait(false);
}

protected async Task<T> PatchAsync<T>(string relativeUri, object? data) {
return await this.SendHttpRequest<T>(new HttpMethod("PATCH"), relativeUri, data).ConfigureAwait(false);
return await SendHttpRequest<T>(new HttpMethod("PATCH"), relativeUri, data).ConfigureAwait(false);
}

protected async Task DeleteAsync(string relativeUri, object? data = null) {
await this.SendHttpRequest<object>(HttpMethod.Delete, relativeUri, data).ConfigureAwait(false);
await SendHttpRequest<object>(HttpMethod.Delete, relativeUri, data).ConfigureAwait(false);
}

private async Task<T?> ProcessHttpResponseMessage<T>(HttpResponseMessage response) {
Expand All @@ -100,7 +100,7 @@ protected async Task DeleteAsync(string relativeUri, object? data = null) {
}

protected void ValidateApiKeyIsOauthAccesstoken(bool isConstructor = false) {
if (!this._apiKey.StartsWith("access_")) {
if (!_apiKey.StartsWith("access_")) {
if (isConstructor) {
throw new InvalidOperationException(
"The provided token isn't an oauth token. You have invoked the method with oauth parameters thus an oauth accesstoken is required.");
Expand Down Expand Up @@ -159,9 +159,8 @@ protected void ValidateRequiredUrlParameter(string parameterName, string paramet
}
}

public void Dispose()
{
if (this._createdHttpClient) {
public void Dispose() {
if (_createdHttpClient) {
_httpClient.Dispose();
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/Mollie.Api/Models/Mandate/MandateResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,41 @@ public class MandateDetails {
/// <summary>
/// The direct debit account holder's name.
/// </summary>
public string ConsumerName { get; set; }
public string? ConsumerName { get; set; }

/// <summary>
/// The direct debit account IBAN.
/// </summary>
public string ConsumerAccount { get; set; }
public string? ConsumerAccount { get; set; }

/// <summary>
/// The direct debit account BIC.
/// </summary>
public string ConsumerBic { get; set; }
public string? ConsumerBic { get; set; }

/// <summary>
/// The credit card holder's name.
/// </summary>
public string CardHolder { get; set; }
public string? CardHolder { get; set; }

/// <summary>
/// The last four digits of the credit card number.
/// </summary>
public string CardNumber { get; set; }
public string? CardNumber { get; set; }

/// <summary>
/// The credit card's label. Note that not all labels can be acquired through Mollie.
/// </summary>
public string CardLabel { get; set; }
public string? CardLabel { get; set; }

/// <summary>
/// Unique alphanumeric representation of credit card, usable for identifying returning customers.
/// </summary>
public string CardFingerprint { get; set; }
public string? CardFingerprint { get; set; }

/// <summary>
/// Expiry date of the credit card card in YYYY-MM-DD format.
/// </summary>
public string CardExpiryDate { get; set; }
public string? CardExpiryDate { get; set; }
}
}
24 changes: 12 additions & 12 deletions src/Mollie.Api/Models/Subscription/SubscriptionResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class SubscriptionResponse : IResponseObject {
/// The subscription's current status, depends on whether the customer has a pending, valid or invalid mandate.
/// See the Mollie.Api.Models.Subscription.SubscriptionStatus class for a full list of known values.
/// </summary>
public string Status { get; set; }
public required string Status { get; init; }

/// <summary>
/// The constant amount that is charged with each subscription payment.
/// </summary>
public Amount Amount { get; set; }
public required Amount Amount { get; init; }

/// <summary>
/// Total number of charges for the subscription to complete.
Expand All @@ -50,12 +50,12 @@ public class SubscriptionResponse : IResponseObject {
/// <summary>
/// Interval to wait between charges like 1 month(s) or 14 days.
/// </summary>
public string Interval { get; set; }
public required string Interval { get; init; }

/// <summary>
/// The start date of the subscription in yyyy-mm-dd format.
/// </summary>
public DateTime StartDate { get; set; }
public DateTime? StartDate { get; set; }

/// <summary>
/// The date of the next scheduled payment in YYYY-MM-DD format. When there will be no next payment, for example
Expand All @@ -67,19 +67,19 @@ public class SubscriptionResponse : IResponseObject {
/// A description unique per customer. This will be included in the payment description along with the charge date in
/// Y-m-d format.
/// </summary>
public string Description { get; set; }
public required string Description { get; init; }

/// <summary>
/// The payment method used for this subscription, either forced on creation by specifying the method parameter, or
/// null if any of the customer's valid mandates may be used. See the Mollie.Api.Models.Payment.PaymentMethod class
/// for a full list of known values.
/// </summary>
public string Method { get; set; }
public string? Method { get; set; }

/// <summary>
/// The mandate used for this subscription. Please note that this parameter can not set together with method.
/// </summary>
public string MandateId { get; set; }
public string? MandateId { get; set; }

/// <summary>
/// The subscription's date of cancellation, in ISO 8601 format.
Expand All @@ -89,29 +89,29 @@ public class SubscriptionResponse : IResponseObject {
/// <summary>
/// The URL Mollie will call as soon a payment status change takes place.
/// </summary>
public string WebhookUrl { get; set; }
public string? WebhookUrl { get; set; }

/// <summary>
/// The optional metadata you provided upon subscription creation. Metadata can for example be used to link a plan to a
/// subscription.
/// </summary>
[JsonConverter(typeof(RawJsonConverter))]
public string Metadata { get; set; }
public string? Metadata { get; set; }

/// <summary>
/// An object with several URL objects relevant to the subscription. Every URL object will contain an href and a type field.
/// </summary>
[JsonProperty("_links")]
public SubscriptionResponseLinks Links { get; set; }
public required SubscriptionResponseLinks Links { get; init; }

/// <summary>
/// Adding an application fee allows you to charge the merchant for each payment in the subscription and
/// transfer these amounts to your own account.
/// </summary>
public ApplicationFee ApplicationFee { get; set; }
public ApplicationFee? ApplicationFee { get; set; }

public T? GetMetadata<T>(JsonSerializerSettings? jsonSerializerSettings = null) {
return Metadata != null ? JsonConvert.DeserializeObject<T>(this.Metadata, jsonSerializerSettings) : default;
return Metadata != null ? JsonConvert.DeserializeObject<T>(Metadata, jsonSerializerSettings) : default;
}
}
}

0 comments on commit cece38c

Please sign in to comment.