CultureQuestORG/SDP2023

View on GitHub

Showing 39 of 57 total issues

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 getDeviceLocation has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          private void getDeviceLocation() {
              /*
               * Get the best and most recent location of the device, which may be null in rare
               * cases when a location is not available.
               */
      Severity: Minor
      Found in app/src/main/java/ch/epfl/culturequest/ui/map/MapsFragment.java - About 4 hrs 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

      File PictureAdapter.java has 338 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      package ch.epfl.culturequest.social;
      
      import static ch.epfl.culturequest.social.RarityLevel.getRarityLevel;
      
      import android.animation.Animator;
      Severity: Minor
      Found in app/src/main/java/ch/epfl/culturequest/social/PictureAdapter.java - About 4 hrs to fix

        Profile has 29 methods (exceeds 20 allowed). Consider refactoring.
        Open

        public class Profile extends Observable {
        
            private String uid, name, username, email, phoneNumber;
            private String profilePicture;
            private Integer score;
        Severity: Minor
        Found in app/src/main/java/ch/epfl/culturequest/social/Profile.java - About 3 hrs to fix

          Method onLocationResult has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

                              @Override
                              public void onLocationResult(@NonNull LocationResult result) {
                                  super.onLocationResult(result);
                                  if (result != null) {
                                      for (Location location : result.getLocations()) {
          Severity: Minor
          Found in app/src/main/java/ch/epfl/culturequest/ui/map/MapsFragment.java - About 2 hrs 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

          Method onCreate has 60 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              @Override
              protected void onCreate(@Nullable Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  AndroidUtils.removeStatusBar(getWindow());
                  Authenticator.checkIfUserIsLoggedIn(this);

            File TournamentManagerApi.java has 255 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            package ch.epfl.culturequest.backend.tournament.apis;
            
            import static androidx.test.InstrumentationRegistry.getTargetContext;
            import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
            import static ch.epfl.culturequest.backend.tournament.apis.SeedApi.generateOrFetchSeedThenStore;

              Method onBindViewHolder has 48 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  @Override
                  public void onBindViewHolder(@NonNull PictureViewHolder holder, int position) {
                      Post post = pictures.get(position);
                      String pictureUrl = post.getImageUrl();
              
              
              Severity: Minor
              Found in app/src/main/java/ch/epfl/culturequest/social/PictureAdapter.java - About 1 hr to fix

                Method onCreate has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    @Override
                    protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_art_description_display);
                        findViewById(R.id.back_button).setOnClickListener(view -> onBackPressed());

                  Method handleLike has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private void handleLike(@NonNull PictureViewHolder holder, Post post) {
                          if (post.getUid().equals(Profile.getActiveProfile().getUid())) {
                              holder.like.setVisibility(View.GONE);
                              return;
                          }
                  Severity: Minor
                  Found in app/src/main/java/ch/epfl/culturequest/social/PictureAdapter.java - About 1 hr to fix

                    Method getOptimalPromptFieldName has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private String getOptimalPromptFieldName(String missingFieldName, BasicArtDescription.ArtType artType){
                    
                            String promptFieldName = "";
                    
                            switch (missingFieldName) {

                      Method getOptimalPromptFieldName has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private String getOptimalPromptFieldName(String missingFieldName, BasicArtDescription.ArtType artType){
                      
                              String promptFieldName = "";
                      
                              switch (missingFieldName) {

                      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

                      Method display_profile has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private void display_profile(String uid) {
                              if (!activeProfile.getUid().equals(uid)) {
                                  Database.getProfile(uid).whenComplete((selectedProfile, e) -> {
                                      this.selectedProfile.setValue(selectedProfile);
                                      username.setValue(selectedProfile.getUsername());

                        Method recoverPotentialMissesAndGetScore has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private CompletableFuture<BasicArtDescription> recoverPotentialMissesAndGetScore(BasicArtDescription incompleteDescription, ArtRecognition recognizedArt, RecoveryState recoveryState, int tryCount) {
                        
                                OpenAIDescriptionApi openAIDescriptionApi = new OpenAIDescriptionApi(service);
                                CompletableFuture<Integer> score = openAIDescriptionApi.getScore(recognizedArt);
                        
                        

                          Method onCreate has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              @Override
                              protected void onCreate(Bundle savedInstanceState) {
                                  super.onCreate(savedInstanceState);
                          
                                  Authenticator.checkIfUserIsLoggedIn(this);
                          Severity: Minor
                          Found in app/src/main/java/ch/epfl/culturequest/NavigationActivity.java - About 1 hr to fix

                            Method getNullFields has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                            Open

                                private ArrayList<String> getNullFields(BasicArtDescription basicArtDescription, RecoveryState recoveryState) {
                            
                                    ArrayList<String> missingFields = new ArrayList<>();
                            
                                    // Get all declared fields (including private ones)

                            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

                            Method createProfile has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public void createProfile(View view) {
                                    //check if username is valid
                                    if (setProblemHintTextIfAny(textView)) return;
                                    String username = textView.getText().toString();
                                    setDefaultPicIfNoneSelected();
                            Severity: Minor
                            Found in app/src/main/java/ch/epfl/culturequest/ProfileCreatorActivity.java - About 1 hr to fix

                              Method updateLeaderboard has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  private void updateLeaderboard() {
                                      String currentUserUid = activeProfile.getUid();
                              
                                      // retrieve the current user's information to be displayed in the leaderboard
                                      currentUsername.setValue(activeProfile.getUsername());

                                Method signIn has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public static CompletableFuture<String> signIn(ComponentActivity activity) {
                                        CompletableFuture<String> future = new CompletableFuture<>();
                                        if (getCurrentUser() == null) {
                                            if (hasConnection(activity)) {
                                                signInLauncher.launch(signInIntent());
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language