app/src/main/java/ch/epfl/culturequest/database/Database.java
File Database.java
has 870 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
package ch.epfl.culturequest.database;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
Database
has 83 methods (exceeds 20 allowed). Consider refactoring. Open
Open
public class Database {
private static final FirebaseDatabase databaseInstance = FirebaseDatabase.getInstance();
private static boolean isEmulatorOn = false;
public static void setPersistenceEnabled() {
Method getLeaderboard
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
Wontfix
public static CompletableFuture<Map<Profile, Integer>> getLeaderboard(Tournament tournament) {
CompletableFuture<Map<Profile, Integer>> future = new CompletableFuture<>();
DatabaseReference tournamentRef = databaseInstance.getReference("tournaments").child(tournament.getTournamentId());
tournamentRef.get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Method updateBadges
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
Wontfix
public static CompletableFuture<HashMap<String, Integer>> updateBadges(String uid, List<String> newbadges) {
CompletableFuture<HashMap<String, Integer>> future = new CompletableFuture<>();
DatabaseReference badgesRef = databaseInstance.getReference("users/" + uid + "/badges");
badgesRef.runTransaction(
new Transaction.Handler() {
Method getTopNFriendsProfiles
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public static CompletableFuture<List<Profile>> getTopNFriendsProfiles(int n) {
DatabaseReference usersRef = databaseInstance.getReference("users");
CompletableFuture<List<Profile>> future = new CompletableFuture<>();
Profile.getActiveProfile().retrieveFriends().thenAccept(friends -> {
//the list of profiles to return (the top n profiles)
Method changeFollow
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private static CompletableFuture<Follows> changeFollow(String follower, String followed, boolean follow) {
CompletableFuture<Follows> future = new CompletableFuture<>();
DatabaseReference followsRef = databaseInstance.getReference("follows").child(follower);
followsRef.runTransaction(new Transaction.Handler() {
Method waitForTournamentGenerationAndFetchIt
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
Wontfix
public static CompletableFuture<Tournament> waitForTournamentGenerationAndFetchIt(AtomicReference<Tournament> fetchedTournament, CompletableFuture<Tournament> future, String tournamentId) {
DatabaseReference dbRef = databaseInstance.getReference();
DatabaseReference tournamentRef = dbRef.child("tournaments").child(tournamentId);
DatabaseReference generatedRef = getDeviceSynchronizationRef().child("generated");
Method handler
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Open
private static Transaction.Handler handler(CompletableFuture<Post> future, String UId, boolean add) {
return new Transaction.Handler() {
@NonNull
@Override
public Transaction.Result doTransaction(@NonNull MutableData mutableData) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"