PolyBooks/sdp_polyBooks

View on GitHub

Showing 76 of 93 total issues

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

private class CompleteBookDatabase(context: Context): BookDatabase {

    val provider =
        CachedBookProvider(
            CachedBookProvider(OLBookDatabase, FBBookDatabase),
Severity: Major
Found in app/src/debug/java/com/github/polybooks/database/Database.kt and 1 other location - About 1 day to fix
app/src/release/java/com/github/polybooks/database/Database.kt on lines 32..68

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

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

private class CompleteBookDatabase(context: Context): BookDatabase {

    val provider =
        CachedBookProvider(
            CachedBookProvider(OLBookDatabase, FBBookDatabase),
app/src/debug/java/com/github/polybooks/database/Database.kt on lines 32..68

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

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

Method rating has a Cognitive Complexity of 70 (exceeds 20 allowed). Consider refactoring.
Open

    private fun rating(sale: Sale){
        bookDB = Database.bookDatabase(this)

        val ratingBar: RatingBar = findViewById(R.id.sale_information_rating)
        ratingBar.rating = 0f

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

    override fun setNavBar() {
        val navBarListener: BottomNavigationView.OnNavigationItemSelectedListener =
            BottomNavigationView.OnNavigationItemSelectedListener { item ->
                when (item.itemId) {
                    R.id.home -> {
app/src/main/java/com/github/polybooks/activities/ListSalesActivity.kt on lines 35..55

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

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

    override fun setNavBar() {
        val navBarListener: BottomNavigationView.OnNavigationItemSelectedListener =
            BottomNavigationView.OnNavigationItemSelectedListener { item ->
                when (item.itemId) {
                    R.id.home -> {
app/src/main/java/com/github/polybooks/activities/ListBooksActivity.kt on lines 34..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 313.

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

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 rating has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private fun rating(sale: Sale){
            bookDB = Database.bookDatabase(this)
    
            val ratingBar: RatingBar = findViewById(R.id.sale_information_rating)
            ratingBar.rating = 0f

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

          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              setContentView(R.layout.activity_fill_sale)
      
              bookDB = Database.bookDatabase(applicationContext)
      Severity: Minor
      Found in app/src/main/java/com/github/polybooks/activities/FillSaleActivity.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 onCreate has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public override fun onCreate(savedInstanceState: Bundle?) {
                super.onCreate(savedInstanceState)
                setContentView(R.layout.activity_signup)
        
                auth = Firebase.auth

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

              override fun onCreate(savedInstanceState: Bundle?) {
                  super.onCreate(savedInstanceState)
                  setContentView(R.layout.activity_login)
          
                  val signInGoogleButton = findViewById<SignInButton>(R.id.sign_in_button)
          Severity: Minor
          Found in app/src/main/java/com/github/polybooks/activities/LoginActivity.kt - About 1 hr to fix

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

                override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BooksViewHolder {
                    val v: View = LayoutInflater.from(parent.context).inflate(R.layout.book_item, parent, false)
                    return BooksViewHolder(v)
                }
            app/src/main/java/com/github/polybooks/adapter/database/InterestAdapter.kt on lines 29..33
            app/src/main/java/com/github/polybooks/adapter/database/SalesAdapter.kt on lines 35..38

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

            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 onCreateViewHolder(parent: ViewGroup, viewType: Int): SalesViewHolder {
                    val v: View = LayoutInflater.from(parent.context).inflate(R.layout.sale_item, parent, false)
                    return SalesViewHolder(v)
                }
            app/src/main/java/com/github/polybooks/adapter/database/BooksAdapter.kt on lines 24..27
            app/src/main/java/com/github/polybooks/adapter/database/InterestAdapter.kt on lines 29..33

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

            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

            /**
             * Defines an ordering for books. DEFAULT is implementation defined.
             * */
            enum class BookOrdering: FieldWithName {
                DEFAULT,
            app/src/main/java/com/github/polybooks/core/Sales.kt on lines 32..44
            app/src/main/java/com/github/polybooks/core/Sales.kt on lines 46..61

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

            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

            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

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

              Severity
              Category
              Status
              Source
              Language