PolyBooks/sdp_polyBooks

View on GitHub

Showing 17 of 93 total issues

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

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

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

                  /**
                   * Function for internal use in OLBookDatabase. Takes the json of a book, and makes a Book from it.
                   * */
                  @RequiresApi(Build.VERSION_CODES.N)
                  private fun parseBook(jsonBook: JsonElement): Book {
              Severity: Minor
              Found in app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt - About 1 hr to fix

                Method scanBarcodes has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        // Inspired from the library guide : https://developers.google.com/ml-kit/vision/barcode-scanning/android#kotlin
                        @SuppressLint("UnsafeExperimentalUsageError")
                        private fun scanBarcodes(imageProxy: ImageProxy) {
                
                            val mediaImage = imageProxy.image

                  Method takePhoto has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      fun takePhoto(view: View) {
                          // TODO offer flash option and other quality of life upgrades
                  
                          // Get a stable reference of the modifiable image capture use case
                          val imageCapture = imageCapture ?: return

                    Method setupNavbar has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    fun setupNavbar(
                        navBar: BottomNavigationView,
                        origin: Context,
                        selectedItem: Int = R.id.default_selected,
                        selectedListener: BottomNavigationView.OnNavigationItemSelectedListener? = null
                    Severity: Minor
                    Found in app/src/main/java/com/github/polybooks/utils/NavBarCreation.kt - About 1 hr to fix

                      Method setParametersButtons has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private fun setParametersButtons() {
                              setTextParameters()
                      
                              mSortParameter = Parameter(
                                  R.id.sale_sort_parameter,

                        Method getInternetPrice has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                        Open

                        fun getInternetPrice(isbn : ISBN): CompletableFuture<String> {
                            return CompletableFuture.supplyAsync {
                                val appId = "?key=1orhhq0s3nrtl4kf93r3"
                                val urlString = "https://booksrun.com/api/price/sell/$isbn$appId"
                                val url = URL(urlString)
                        Severity: Minor
                        Found in app/src/main/java/com/github/polybooks/utils/InternetPrice.kt - 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

                        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

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

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

                            Method scanBarcodes has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                            Open

                                    // Inspired from the library guide : https://developers.google.com/ml-kit/vision/barcode-scanning/android#kotlin
                                    @SuppressLint("UnsafeExperimentalUsageError")
                                    private fun scanBarcodes(imageProxy: ImageProxy) {
                            
                                        val mediaImage = imageProxy.image
                            Severity: Minor
                            Found in app/src/main/java/com/github/polybooks/activities/ScanBarcodeActivity.kt - 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

                            Severity
                            Category
                            Status
                            Source
                            Language