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

Improving code quality with SonarCloud #5

Merged
merged 21 commits into from
May 17, 2024

Conversation

sutheo17
Copy link
Contributor

I have fixed the high severity cases of reliability and maintainability according to SonarCloud. They did prove to be real concerns, so I made the changes accordingly. This included the following changes:

RCIR -> reduce complexity, increase readability

Cisterns.java

  • Random object initialized once in the class
  • Removed unused line

Game.java

  • Closed the input / output streams with a finally block
  • NotifyAll renamed to NotifyAllTimePassed to avoid confusion with Object.notifyAll
  • Settings method have been made static
  • Round method refactored to RCIR

    added several sub-methods

  • Random object initialized once in the class

GameView.java

  • x variable renamed to x_cord in order not to mistake with Component.x
  • y variable renamed to x_cord in order not to mistake with Component.y
  • a constant string literal have been added to the mountain image's path

Mountains.java

  • added an explanatory comment to the SetStorage method

Pipe.java

  • Path method refactored to reduce complexity and to increase readability
  • ChangePipe method refactored to RCIR

    removed unnecessary nesting

  • Random object initialized once in the class

PipeView.java

  • PaintComponent method refactored to RCIR

removed unnecessary lines
added sub-methods

Player.java

  • a constant string literal have been added containing an error message which pops up when a player in unable to move
  • Move method refactored to RCIR

    added sub-methods

  • MoveToElement method refactored to RCIR

    added sub-methods
    removed unused codes
    added TODO functionality

TableView.java

  • added context to unused methods with comments
  • KeyPressed method refactored to RCIR

    added sub-methods
    removed unnecessary nesting
    simplified if-else cases

View.java

  • x variable renamed to x_cord in order not to mistake with Component.x
  • y variable renamed to x_cord in order not to mistake with Component.y
  • added an explanatory comment to the unused methods

Sütheö István added 18 commits May 17, 2024 12:46
A Random object should be only initialized once for better efficiency and randomness.
Commented out program logic should not persist inside the finished code.
Try-with-resource pattern added.
A Random object should be only initialized once for better efficiency and randomness.
A Random object should be only initialized once for better efficiency and randomness.

I also fixed a typo where I left the out the class type in Pipe.java.
It has been renamed to NotifyAllTimePassed to prevent confusion with Object.noifyAll method.
If there would be multiple threads, this is the safe way.
It was too complex, too long and was overwhelming. I have added several assistant method to fix this problem.
To avoid confusion with a filed of Component class.
To we don't have to duplicate its path in the methods.
Explaining why the method is empty.
It was too complex, too long and was overwhelming. I have added several assistant method to fix this problem.
It was too complex, too long and was overwhelming. I have added several assistant method to fix this problem.
To improve readability and to reduce the complexity of the method.
It has been to complex, several assistant methods have been added.

I also added an error message constant to reduce code duplication.
Readability improvid, it was too complex, so I made several helper methods to fix this issue.
I also added comments to the unused methods.
It was too long and was to confusing. I added several sub-methods and also removed unnecessary nesting.
@sutheo17 sutheo17 self-assigned this May 17, 2024
@sutheo17 sutheo17 linked an issue May 17, 2024 that may be closed by this pull request
Sütheö István added 3 commits May 17, 2024 16:45
string -> String (Java)
Too much C# lately.
Also added const keyword.
Too much C# as I have said.
Fixed the Maven build errors. There were several small bugifixes.
Copy link

sonarcloud bot commented May 17, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

Copy link
Contributor

@gerencsermate gerencsermate left a comment

Choose a reason for hiding this comment

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

I checked the changes, everything seems fine.

}
}catch (NumberFormatException e){System.out.println("Rossz parametert adtal meg");}
// Végigmegyünk az összes játékoson, és feldolgozzuk a körüket mint Szabotőr
for (int i = 0; i < NumberOfPlayers; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Much easier to read this code

@sutheo17 sutheo17 merged commit 041534c into main May 17, 2024
1 of 2 checks passed
@sutheo17
Copy link
Contributor Author

@gerencsermate have reviewed my work. I will merge this branch into main.

@sutheo17 sutheo17 added the enhancement New feature or request label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improving code quality with SonarCloud
2 participants