MarshallAsch/veil-droid

View on GitHub
app/src/main/java/ca/marshallasch/veil/database/Database.java

Summary

Maintainability
F
6 days
Test Coverage

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

package ca.marshallasch.veil.database;

import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
Severity: Major
Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 2 days to fix

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

    @ThreadSafe
    public class Database extends SQLiteOpenHelper
    {
        private static String DATABASE_NAME = "contentDiscoveryTables";
        private static final int DATABASE_VERSION = 10;
    Severity: Minor
    Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 6 hrs to fix

      Method login has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Wontfix

          @Nullable
          @WorkerThread
          public DhtProto.User login(@Nullable String email,@Nullable  String password) {
      
              if (email == null || password == null) {
      Severity: Minor
      Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

        Method updatePassword has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            @WorkerThread
            public boolean updatePassword(@Nullable  String email, @Nullable String oldPassword, @Nullable String newPassword) {
        
                if (email == null || oldPassword == null || newPassword == null) {
                    return false;
        Severity: Minor
        Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

          Method getUser has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              @Nullable
              @WorkerThread
              public DhtProto.User getUser(@Nullable String uuid) {
          
                  if (uuid == null) {
          Severity: Minor
          Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

            Method updateLogSync has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                @WorkerThread
                public boolean updateLogSync(@NonNull String uuid, int additionalSize, int numRecords) {
            
                    String selection = SyncStatsEntry.COLUMN_DATA_SEND_ID + " = ?";
                    String[] selectionArgs = { uuid };
            Severity: Minor
            Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

              Method getAllHashesByStatus has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  @WorkerThread
                  public List<String> getAllHashesByStatus(int status){
                      String[] projection = {
                              KnownPostsEntry.COLUMN_POST_HASH,
                              KnownPostsEntry.COLUMN_COMMENT_HASH};
              Severity: Minor
              Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

                Method dumpKnownPosts has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    @WorkerThread
                    @NonNull
                    public List<Pair<String, String>> dumpKnownPosts(@Nullable Date since) {
                
                        List<Pair<String, String>> hashes = new ArrayList<>();
                Severity: Minor
                Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

                  Method getTimeLastSentData has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      @WorkerThread
                      public Date getTimeLastSentData(String peerID) {
                  
                          Date time = new Date(0);
                  
                  
                  Severity: Minor
                  Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

                    Method dumpKnownPosts has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        @WorkerThread
                        @NonNull
                        public List<Pair<String, String>> dumpKnownPosts() {
                    
                            String[] projection = {
                    Severity: Minor
                    Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

                      Method getCommentHashes has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          @WorkerThread
                          public List<String> getCommentHashes(String postHash) {
                      
                              String[] projection = {
                                      KnownPostsEntry.COLUMN_COMMENT_HASH
                      Severity: Minor
                      Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 1 hr to fix

                        Method onUpgrade has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            @Override
                            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                                if(oldVersion < 3){
                                    Migrations.upgradeV3(db);
                                }
                        Severity: Minor
                        Found in app/src/main/java/ca/marshallasch/veil/database/Database.java - About 35 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

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            @WorkerThread
                            public double getFastestTime(@IntRange(from = 0, to = 3) int protocolVersion) {
                        
                                String selection = SyncStatsEntry.COLUMN_MESSAGE_TYPE + " = ? AND " +
                                        SyncStatsEntry.COLUMN_TIMESTAMP_RECEIVED  + " not NULL";
                        app/src/main/java/ca/marshallasch/veil/database/Database.java on lines 1430..1457

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 146.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            @WorkerThread
                            public double getSlowestTime(@IntRange(from = 0, to = 3) int protocolVersion) {
                        
                                String selection = SyncStatsEntry.COLUMN_MESSAGE_TYPE + " = ? AND " +
                                        SyncStatsEntry.COLUMN_TIMESTAMP_RECEIVED  + " not NULL";
                        app/src/main/java/ca/marshallasch/veil/database/Database.java on lines 1467..1494

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 146.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            @WorkerThread
                            public int getTotalEntries(@IntRange(from = 0, to = 3) int protocolVersion) {
                        
                                String selection = SyncStatsEntry.COLUMN_MESSAGE_TYPE + " = ?";
                                String[] selectionArgs = {String.valueOf(protocolVersion)};
                        app/src/main/java/ca/marshallasch/veil/database/Database.java on lines 1274..1299

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 120.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            @WorkerThread
                            public int getTotalMessageSize(@IntRange(from = 0, to = 3) int protocolVersion) {
                        
                                String selection = SyncStatsEntry.COLUMN_MESSAGE_TYPE + " = ?";
                                String[] selectionArgs = {String.valueOf(protocolVersion)};
                        app/src/main/java/ca/marshallasch/veil/database/Database.java on lines 1346..1371

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 120.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            @WorkerThread
                            public boolean unblockUser(@Size(max = 36) String userID)
                            {
                                if (userID == null) {
                                    return false;
                        app/src/main/java/ca/marshallasch/veil/database/Database.java on lines 306..325

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 80.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            @WorkerThread
                            public boolean unregisterForNotification(@Size(max = 36) String hash) {
                        
                                if (hash == null) {
                                    return false;
                        app/src/main/java/ca/marshallasch/veil/database/Database.java on lines 222..243

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 80.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                while(cursor.moveToNext()) {
                                    postHash = cursor.getString(cursor.getColumnIndexOrThrow(KnownPostsEntry.COLUMN_POST_HASH));
                                    commentHash = cursor.getString(cursor.getColumnIndexOrThrow(KnownPostsEntry.COLUMN_COMMENT_HASH));
                        
                                    // add the hash to the list
                        Severity: Minor
                        Found in app/src/main/java/ca/marshallasch/veil/database/Database.java and 1 other location - About 45 mins to fix
                        app/src/main/java/ca/marshallasch/veil/database/Database.java on lines 969..975

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 56.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Identical blocks of code found in 2 locations. Consider refactoring.
                        Open

                                while(cursor.moveToNext()) {
                                    postHash = cursor.getString(cursor.getColumnIndexOrThrow(KnownPostsEntry.COLUMN_POST_HASH));
                                    commentHash = cursor.getString(cursor.getColumnIndexOrThrow(KnownPostsEntry.COLUMN_COMMENT_HASH));
                        
                                    // add the hash to the list
                        Severity: Minor
                        Found in app/src/main/java/ca/marshallasch/veil/database/Database.java and 1 other location - About 45 mins to fix
                        app/src/main/java/ca/marshallasch/veil/database/Database.java on lines 1027..1033

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 56.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        There are no issues that match your filters.

                        Category
                        Status