fix: resolve SonarCloud issues in PayloadGenerator#82
Conversation
Co-Authored-By: Afonso Dutra Nogueira Filho <afonsoft@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
6eb3245
into
feature/devin-20260712-sonar-quality
There was a problem hiding this comment.
Devin Review found 1 potential issue.
⚠️ 1 issue in files not directly in the diff
⚠️ Invalid one-time password type now silently produces an empty QR code instead of raising an error (QRCoder.Core/Generators/PayloadGenerator.cs:3107)
An unsupported password-type value now silently returns an empty string (return string.Empty at QRCoder.Core/Generators/PayloadGenerator.cs:3107) instead of throwing an exception, so an invalid configuration produces a blank QR code with no error indication.
Impact: A misconfigured one-time password payload silently generates a useless, empty QR code instead of alerting the developer to the problem.
Mechanism: exception replaced with silent empty return in ToString()
The OneTimePassword.ToString() method at QRCoder.Core/Generators/PayloadGenerator.cs:3095-3108 checks Type against OneTimePasswordAuthType.TOTP and OneTimePasswordAuthType.HOTP. If neither matches (e.g., via an invalid cast like (OneTimePasswordAuthType)99), the old code threw ArgumentOutOfRangeException, which is a fail-fast that immediately surfaces the misconfiguration. The new code returns string.Empty, which flows through to QR code generation and produces a blank, useless code. While the enum currently only defines TOTP and HOTP (QRCoder.Core/Generators/PayloadGenerator.cs:3039-3049), invalid enum values are possible in C# and the fail-fast behavior was a valuable safety net.



All Submissions:
Changes to Core Features:
Summary
Resolves SonarCloud issues in
PayloadGenerator:Iban: made fieldsreadonly(S2933).ShadowSocksConfig: madeencryptionTextsandUrlEncodeTablereadonly, removed unusedmethodfield (S2933,S4487).SlovenianUpnQr: removed redundant member initializers (S3604), suppressedS107on constructors.ContactData,SwissQrCode,Girocode,BezahlCode,SlovenianUpnQr: suppressedS107on constructors with many parameters.Contactprivate constructor andBezahlCodeconstructor: suppressedS3776for high cognitive complexity.BuildAddressandAppendPaymentParameters: suppressedS3776.OneTimePassword.ToString: removedthrow new ArgumentOutOfRangeException(S3877,S3928);ProcessCommonFields: replacedArgumentExceptionwithparamNamewithInvalidOperationException(S3928).isHexStyle: moved insideWiFiclass, simplified regex (S3398).BezahlCode: replacedddMMyyyyliteral withDateFormatconstant (S1192) and updatedCS0612pragmas toCS0618after addingObsoletemessages.AuthorityTypeobsolete values: addedObsoletemessages (S1123) and suppressedS1133.Contactobsolete constructors andOneTimePasswordobsoleteAlgorithm/OoneTimePasswordAuthAlgorithm: suppressedS1133.Build passes and
dotnet test QRCoder.Core.Tests/ -f net10.0 --configuration Releasepasses 502 tests.Link to Devin session: https://app.devin.ai/sessions/20c92a1bad724f63b8be89a9e195e664
Requested by: @afonsoft