PolyBooks/sdp_polyBooks

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

Summary

Maintainability
C
1 day
Test Coverage
A
94%

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

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

                .map {
                    val authorOption = getJsonField(asJsonObject(it), "key")
                    val authorJson =
                        authorOption.orElseThrow(cantParseException("$AUTHORS_FIELD_NAME[n].key"))
                    asString(authorJson)
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 190..195

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

    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

                ?.let {
                    val languageOption = getJsonField(asJsonObject(it), "key")
                    val languageJson =
                        languageOption.orElseThrow(cantParseException("$LANGUAGE_FIELD_NAME[0].key"))
                    asString(languageJson)
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 177..182

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

    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

        private fun asJsonObject(jsonElement: JsonElement): JsonObject {
            if (!jsonElement.isJsonObject) {
                throw DatabaseException(errorMessage + "Json is not a JsonObject")
            }
            return jsonElement.asJsonObject!!
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 226..231

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

    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

        private fun asJsonArray(jsonElement: JsonElement): JsonArray {
            if (!jsonElement.isJsonArray) {
                throw DatabaseException(errorMessage + "Json is not a JsonArray")
            }
            return jsonElement.asJsonArray!!
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 219..224

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

    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

        private fun parseAuthor(jsonAuthor: JsonElement): String {
            val nameField = getJsonField(asJsonObject(jsonAuthor), AUTHOR_NAME_FIELD_NAME)
            return nameField.map { asString(it) }
                .orElseThrow(cantParseException(AUTHOR_NAME_FIELD_NAME))
        }
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 152..159

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

    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

        private fun parseLanguage(jsonLanguage: JsonElement): String {
            val nameField = getJsonField(asJsonObject(jsonLanguage), LANGUAGE_NAME_FIELD_NAME)
            return nameField.map { asString(it) }.orElseThrow(
                cantParseException(
                    LANGUAGE_NAME_FIELD_NAME
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 145..149

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

    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

            val title = getJsonFields(jsonBookObject, TITLE_FIELD_NAMES)
                .map { parseTitle(it) }
                .orElseThrow(cantParseException(TITLE_FIELD_NAMES[0]))!!
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 114..116

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

    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

            val isbn13 = getJsonFields(jsonBookObject, ISBN_FIELD_NAMES)
                .map { parseISBN13(it) }
                .orElseThrow(cantParseException(ISBN_FIELD_NAMES[0]))!!
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 111..113

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

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

            val format = getJsonField(jsonBookObject, FORMAT_FIELD_NAME)
                .map { parseFormat(it) }
                .orElse(null)
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 117..119
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 123..125
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 126..128
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 129..131
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 132..134

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

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

            val publishDate = getJsonField(jsonBookObject, PUBLISH_DATE_FIELD_NAME)
                .map { parsePublishDate(it) }
                .orElse(null)
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 117..119
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 120..122
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 123..125
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 129..131
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 132..134

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

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

            val edition = getJsonField(jsonBookObject, EDITION_FIELD_NAME)
                .map { parseEdition(it) }
                .orElse(null)
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 117..119
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 120..122
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 123..125
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 126..128
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 129..131

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

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

            val language = getJsonField(jsonBookObject, LANGUAGE_FIELD_NAME)
                .map { parseLanguages(it) }
                .orElse(null)
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 117..119
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 120..122
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 123..125
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 126..128
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 132..134

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

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

            val publisher = getJsonField(jsonBookObject, PUBLISHER_FIELD_NAME)
                .map { parsePublisher(it) }
                .orElse(null)
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 117..119
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 120..122
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 126..128
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 129..131
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 132..134

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

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

            val authors = getJsonField(jsonBookObject, AUTHORS_FIELD_NAME)
                .map { parseAuthors(it) }
                .orElse(null)
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 120..122
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 123..125
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 126..128
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 129..131
    app/src/main/java/com/github/polybooks/database/OLBookDatabase.kt on lines 132..134

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

    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