btelman96/letsrobot-android

View on GitHub
letsrobotandroid-api/src/main/java/tv/letsrobot/android/api/robot/drivers/UsbService.java

Summary

Maintainability
C
7 hrs
Test Coverage

Method findSerialPortDevice has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    private void findSerialPortDevice() {
        // This snippet will try to open the first encountered usb device connected, excluding usb root hubs
        HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
        if (!usbDevices.isEmpty()) {
            boolean keep = true;

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 onReceive has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        @Override
        public void onReceive(Context arg0, Intent arg1) {
            if (arg1.getAction().equals(ACTION_USB_PERMISSION)) {
                Log.d("USB", "ACTION_USB_PERMISSION");
                boolean granted = arg1.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED);

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

        @Override
        public void run() {
            serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
            if (serialPort != null) {
                if (serialPort.open()) {

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

            @Override
            public void onReceive(Context arg0, Intent arg1) {
                if (arg1.getAction().equals(ACTION_USB_PERMISSION)) {
                    Log.d("USB", "ACTION_USB_PERMISSION");
                    boolean granted = arg1.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED);

      Method findSerialPortDevice has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private void findSerialPortDevice() {
              // This snippet will try to open the first encountered usb device connected, excluding usb root hubs
              HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
              if (!usbDevices.isEmpty()) {
                  boolean keep = true;

        Method run has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

                @Override
                public void run() {
                    serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
                    if (serialPort != null) {
                        if (serialPort.open()) {

        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

        There are no issues that match your filters.

        Category
        Status