Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetConnectionIdFromUri Method to ConnectionIdHelper #5231

Merged

Conversation

ugras-ergun-sonarsource
Copy link
Contributor

Fixes #5230

@ugras-ergun-sonarsource ugras-ergun-sonarsource changed the base branch from master to feature/sloop-rule-meta-data February 15, 2024 13:39
@@ -33,6 +35,22 @@ internal class ConnectionIdHelper : IConnectionIdHelper
private const string SonarQubePrefix = "sq|";
private static readonly Uri SonarCloudUri = new Uri("https://sonarcloud.io");

public string GetConnectionIdFromUri(string uriString, string organisation)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BoundSonarQubeProject has Uri property, why do you use string here? The other method of this class also returns Uri and not string

@@ -33,6 +35,22 @@ internal class ConnectionIdHelper : IConnectionIdHelper
private const string SonarQubePrefix = "sq|";
private static readonly Uri SonarCloudUri = new Uri("https://sonarcloud.io");

public string GetConnectionIdFromUri(Uri uri, string organisation)
{
if (uri is not null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invert if to reduce nesting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will be that useful because then we'll need to have more return points (since this way it returns null when organisation is missing)

{
if (uri == SonarCloudUri)
{
if (!string.IsNullOrWhiteSpace(organisation)) { return SonarCloudPrefix + organisation; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newlines missing in if body

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's to reduce clutter I think the expression is simple enough to read easily.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're treating a symptom here. This method is hard to read, I completely missed the branch where organization is null (is that even a possibility?)

var actualConnectionId = testSubject.GetConnectionIdFromUri(null, "something");

actualConnectionId.Should().BeNull();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test that uri == GetUriFromConnectionId(GetConnectionIdFromUri(uri))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple of small suggestions, otherwise LGTM

Copy link

@ugras-ergun-sonarsource ugras-ergun-sonarsource merged commit 5d81b54 into feature/sloop-rule-meta-data Feb 16, 2024
4 checks passed
@ugras-ergun-sonarsource ugras-ergun-sonarsource deleted the ue/connectionIDGenerator branch February 16, 2024 12:32
Comment on lines +47 to +50
if (!string.IsNullOrWhiteSpace(organisation))
{
return SonarCloudPrefix + organisation;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for a refactoring change in the next PR:
This would be easier to understand like this:

return string.IsNullOrWhiteSpace(organization)
    ? null
    : SonarCloudPrefix + organization;

and then removing the least return null

@@ -33,6 +35,28 @@ internal class ConnectionIdHelper : IConnectionIdHelper
private const string SonarQubePrefix = "sq|";
private static readonly Uri SonarCloudUri = new Uri("https://sonarcloud.io");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C#9 target-typed null can be useful here (it's not useful ultimately everywhere, this is a place where it is)

private static readonly Uri SonarCloudUri = new("https://sonarcloud.io");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GetConnectionIdFromUri Method to ConnectionIdHelper
3 participants