PolyBooks/sdp_polyBooks

View on GitHub
app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt

Summary

Maintainability
D
1 day
Test Coverage
A
94%

File FBSaleDatabase.kt has 288 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package com.github.polybooks.database

import com.github.polybooks.core.*
import com.github.polybooks.database.SaleOrdering.*
import com.github.polybooks.utils.listOfFuture2FutureOfList
Severity: Minor
Found in app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt - About 2 hrs to fix

    Method getAll has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
    Open

            override fun getAll(): CompletableFuture<List<Sale>> {
                return if (interests == null && title == null && isbn == null) { //In this case we should not look in the book database
                    doQueries(filterQuery(saleRef)).thenCompose { snapshotsToSales(it) }
                        .thenApply { order(it, ordering) }
                } else {
    Severity: Minor
    Found in app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt - About 1 hr 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 filterQuery has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            //This functions computes the set of queries to execute in order to get the desired Sales.
            //We need to return a set of queries because Firebase doesn't allow for more than one IN clause.
            //Ergo, we need to do multiple queries.
            private fun filterQuery(q: Query): List<Query> {
                var queries = listOf(q)
    Severity: Minor
    Found in app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt - About 1 hr to fix

      Method addSale has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              bookISBN: ISBN,
              seller: User,
              price: Float,
              condition: BookCondition,
              state: SaleState,
      Severity: Minor
      Found in app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt - About 45 mins to fix

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

                    conditions?.let {
                        queries = queries.flatMap { query ->
                            conditions!!.map { condition ->
                                query.whereEqualTo(
                                    SaleFields.CONDITION.fieldName,
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 108..112

        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 113.

        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

                    states?.let {
                        queries = queries.flatMap { query ->
                            states!!.map { state -> query.whereEqualTo(SaleFields.STATE.fieldName, state) }
                        }
                    }
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 113..122

        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 113.

        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 3 locations. Consider refactoring.
        Open

                override fun searchByState(state: Set<SaleState>): SaleQuery {
                    if (state.isNotEmpty()) this.states = state
                    else this.states = null
                    return this
                }
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 39..43
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 56..60

        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 106.

        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 3 locations. Consider refactoring.
        Open

                override fun onlyIncludeInterests(interests: Set<Interest>): SaleQuery {
                    if (interests.isNotEmpty()) this.interests = interests
                    else this.interests = null
                    return this
                }
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 50..54
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 56..60

        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 106.

        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 3 locations. Consider refactoring.
        Open

                override fun searchByCondition(condition: Set<BookCondition>): SaleQuery {
                    if (condition.isNotEmpty()) this.conditions = condition
                    else this.conditions = null
                    return this
                }
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 39..43
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 50..54

        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 106.

        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

                    maxPrice?.let {
                        queries = queries.map {
                            it.whereLessThanOrEqualTo(
                                SaleFields.PRICE.fieldName,
                                maxPrice!!
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 92..99

        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 83.

        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

                    minPrice?.let {
                        queries = queries.map {
                            it.whereGreaterThanOrEqualTo(
                                SaleFields.PRICE.fieldName,
                                minPrice!!
        app/src/main/java/com/github/polybooks/database/FBSaleDatabase.kt on lines 100..107

        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 83.

        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

            override fun addSale(
                bookISBN: ISBN,
                seller: User,
                price: Float,
                condition: BookCondition,
        app/src/main/java/com/github/polybooks/database/SaleDatabase.kt on lines 35..40

        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 70.

        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