CultureQuestORG/SDP2023

View on GitHub
app/src/main/java/ch/epfl/culturequest/database/Database.java

Summary

Maintainability
F
4 days
Test Coverage
B
83%

File Database.java has 870 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package ch.epfl.culturequest.database;

import android.annotation.SuppressLint;

import androidx.annotation.NonNull;
Severity: Major
Found in app/src/main/java/ch/epfl/culturequest/database/Database.java - About 2 days to fix

    Database has 83 methods (exceeds 20 allowed). Consider refactoring.
    Open

    public class Database {
        private static final FirebaseDatabase databaseInstance = FirebaseDatabase.getInstance();
        private static boolean isEmulatorOn = false;
    
        public static void setPersistenceEnabled() {
    Severity: Major
    Found in app/src/main/java/ch/epfl/culturequest/database/Database.java - About 1 day to fix

      Method getLeaderboard has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      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()) {
      Severity: Minor
      Found in app/src/main/java/ch/epfl/culturequest/database/Database.java - About 1 hr to fix

        Method updateBadges has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        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() {
        Severity: Minor
        Found in app/src/main/java/ch/epfl/culturequest/database/Database.java - About 1 hr to fix

          Method getTopNFriendsProfiles has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          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)
          Severity: Minor
          Found in app/src/main/java/ch/epfl/culturequest/database/Database.java - About 1 hr to fix

            Method changeFollow has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            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() {
            Severity: Minor
            Found in app/src/main/java/ch/epfl/culturequest/database/Database.java - About 1 hr to fix

              Method waitForTournamentGenerationAndFetchIt has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              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");
              Severity: Minor
              Found in app/src/main/java/ch/epfl/culturequest/database/Database.java - About 1 hr to fix

                Method handler has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                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) {
                Severity: Minor
                Found in app/src/main/java/ch/epfl/culturequest/database/Database.java - About 55 mins to fix

                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"

                Further reading

                There are no issues that match your filters.

                Category
                Status