XYOracleNetwork/sdk-ble-android

View on GitHub
ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYBluetoothDevice.kt

Summary

Maintainability
D
3 days
Test Coverage

Method checkForExit has a Cognitive Complexity of 105 (exceeds 20 allowed). Consider refactoring.
Open

    // this should only be called from the onEnter function so that
    // there is one onExit for every onEnter
    private fun checkForExit() {
        if (!exitEnabled) {
            return

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 XYBluetoothDevice.kt has 283 lines of code (exceeds 250 allowed). Consider refactoring.
Open

package network.xyo.ble.generic.devices

import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGatt
import android.content.Context

    Method checkForExit has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        // this should only be called from the onEnter function so that
        // there is one onExit for every onEnter
        private fun checkForExit() {
            if (!exitEnabled) {
                return

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

                  override fun getDevicesFromScanResult(context: Context, scanResult: XYScanResult, globalDevices: ConcurrentHashMap<String, XYBluetoothDevice>, foundDevices: HashMap<String, XYBluetoothDevice>) {
      
                      getDevicesFromServices(context, scanResult, globalDevices, foundDevices)
                      getDevicesFromManufacturers(context, scanResult, globalDevices, foundDevices)
      
      

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

                private fun getDevicesFromServices(context: Context, scanResult: XYScanResult, globalDevices: ConcurrentHashMap<String, XYBluetoothDevice>, newDevices: HashMap<String, XYBluetoothDevice>) {
        ble-android-library/src/main/kotlin/network/xyo/ble/devices/apple/XYAppleBluetoothDevice.kt on lines 40..40
        ble-android-library/src/main/kotlin/network/xyo/ble/devices/apple/XYIBeaconBluetoothDevice.kt on lines 147..152
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYBluetoothDevice.kt on lines 287..287
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYBluetoothDevice.kt on lines 308..308
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYCreator.kt on lines 11..11

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

                    override fun getDevicesFromScanResult(context: Context, scanResult: XYScanResult, globalDevices: ConcurrentHashMap<String, XYBluetoothDevice>, foundDevices: HashMap<String, XYBluetoothDevice>) {
        ble-android-library/src/main/kotlin/network/xyo/ble/devices/apple/XYAppleBluetoothDevice.kt on lines 40..40
        ble-android-library/src/main/kotlin/network/xyo/ble/devices/apple/XYIBeaconBluetoothDevice.kt on lines 147..152
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYBluetoothDevice.kt on lines 287..287
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYBluetoothDevice.kt on lines 297..297
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYCreator.kt on lines 11..11

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

                private fun getDevicesFromManufacturers(context: Context, scanResult: XYScanResult, globalDevices: ConcurrentHashMap<String, XYBluetoothDevice>, newDevices: HashMap<String, XYBluetoothDevice>) {
        ble-android-library/src/main/kotlin/network/xyo/ble/devices/apple/XYAppleBluetoothDevice.kt on lines 40..40
        ble-android-library/src/main/kotlin/network/xyo/ble/devices/apple/XYIBeaconBluetoothDevice.kt on lines 147..152
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYBluetoothDevice.kt on lines 297..297
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYBluetoothDevice.kt on lines 308..308
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/devices/XYCreator.kt on lines 11..11

        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

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

            override fun updateBluetoothDevice(device: BluetoothDevice?) {
        
                if (device?.address != this.device?.address || this.device == null) {
                    // log.info("updateBluetoothDevice: Updating Device [$hash]")
                    // log.info("updateBluetoothDevice: Updating Device [new = ${device?.address}, old = ${this.device?.address}]")
        ble-android-library/src/main/kotlin/network/xyo/ble/generic/gatt/peripheral/XYBluetoothGattClient.kt on lines 20..24

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

        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