Hackman238/legion

View on GitHub
ui/view.py

Summary

Maintainability
F
1 wk
Test Coverage

File view.py has 1274 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python

"""
LEGION (https://shanewilliamscott.com)
Copyright (c) 2024 Shane Scott
Severity: Major
Found in ui/view.py - About 3 days to fix

    View has 113 functions (exceeds 50 allowed). Consider refactoring.
    Open

    class View(QtCore.QObject):
        tick = QtCore.pyqtSignal(int, name="changed")                       # signal used to update the progress bar
        
        def __init__(self, viewState: ViewState, ui, ui_mainwindow, shell: Shell, app, loop):
            QtCore.QObject.__init__(self)
    Severity: Major
    Found in ui/view.py - About 1 day to fix

      Function contextMenuServiceNamesTableView has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

          def contextMenuServiceNamesTableView(self, pos):
              if len(self.ui.ServiceNamesTableView.selectionModel().selectedRows()) > 0:
                  row = self.ui.ServiceNamesTableView.selectionModel().selectedRows()[len(
                      self.ui.ServiceNamesTableView.selectionModel().selectedRows())-1].row()
                  self.viewState.service_clicked = self.ServiceNamesTableModel.getServiceNameForRow(row)
      Severity: Minor
      Found in ui/view.py - About 5 hrs 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

      Function callAddHosts has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def callAddHosts(self):
              hostListStr = str(self.adddialog.txtHostList.toPlainText()).replace(';',' ')
              nmapOptions = []
              scanMode = 'Unset'
      
      
      Severity: Minor
      Found in ui/view.py - About 2 hrs 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

      Function contextMenuServicesTableView has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def contextMenuServicesTableView(self, pos):
              if len(self.ui.ServicesTableView.selectionModel().selectedRows()) > 0:
                  # if there is only one row selected, get service name
                  if len(self.ui.ServicesTableView.selectionModel().selectedRows()) == 1:
                      row = self.ui.ServicesTableView.selectionModel().selectedRows()[len(
      Severity: Minor
      Found in ui/view.py - About 2 hrs 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

      Function toolHostsClick has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def toolHostsClick(self):
              if self.ui.ToolHostsTableView.selectionModel().selectedRows():
                  row = self.ui.ToolHostsTableView.selectionModel().selectedRows()[len(
                      self.ui.ToolHostsTableView.selectionModel().selectedRows())-1].row()
                  self.viewState.tool_host_clicked = self.ToolHostsTableModel.getProcessIdForRow(row)
      Severity: Minor
      Found in ui/view.py - About 2 hrs 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

      Function updateInformationView has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def updateInformationView(self, hostIP):
      
              if hostIP:
                  host = self.controller.getHostInformation(hostIP)
                  
      Severity: Minor
      Found in ui/view.py - About 2 hrs 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

      Function saveProjectAs has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def saveProjectAs(self):
              self.ui.statusbar.showMessage('Saving..')
              log.info('Saving project..')
      
              self.controller.saveProject(self.viewState.lastHostIdClicked, self.ui.NotesTextEdit.toPlainText())
      Severity: Minor
      Found in ui/view.py - 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

      Function closeHostToolTab has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def closeHostToolTab(self, index):
              currentTabIndex = self.ui.ServicesTabWidget.currentIndex()      # remember the currently selected tab
              self.ui.ServicesTabWidget.setCurrentIndex(index) # select the tab for which the cross button was clicked
      
              currentWidget = self.ui.ServicesTabWidget.currentWidget()
      Severity: Minor
      Found in ui/view.py - 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

      Function closeBruteTab has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def closeBruteTab(self, index):
              currentTabIndex = self.ui.BruteTabWidget.currentIndex()         # remember the currently selected tab
              # select the tab for which the cross button was clicked
              self.ui.BruteTabWidget.setCurrentIndex(index)
              
      Severity: Minor
      Found in ui/view.py - 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

      Function contextToolHostsTableContextMenu has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def contextToolHostsTableContextMenu(self, pos):
              if len(self.ui.ToolHostsTableView.selectionModel().selectedRows()) > 0:
                  
                  row = self.ui.ToolHostsTableView.selectionModel().selectedRows()[len(
                      self.ui.ToolHostsTableView.selectionModel().selectedRows())-1].row()
      Severity: Minor
      Found in ui/view.py - 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

      Function openExistingProject has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def openExistingProject(self):
              if self.dealWithCurrentProject():
                  filename = QtWidgets.QFileDialog.getOpenFileName(
                      self.ui.centralwidget, 'Open project', self.controller.getCWD(),
                      filter='Legion session (*.legion);; Sparta session (*.sprt)')[0]
      Severity: Minor
      Found in ui/view.py - 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

      Function startConnections has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def startConnections(self):  # signal initialisations (signals/slots, actions, etc)
              ### MENU ACTIONS ###
              self.connectCreateNewProject()
              self.connectOpenExistingProject()
              self.connectSaveProject()
      Severity: Minor
      Found in ui/view.py - About 1 hr to fix

        Function switchTabClick has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def switchTabClick(self):
                if self.ServiceNamesTableModel:                                 # fixes bug when switching tabs at start-up
                    selectedTab = self.ui.HostsTabWidget.tabText(self.ui.HostsTabWidget.currentIndex())
                
                    if selectedTab == 'Hosts':
        Severity: Minor
        Found in ui/view.py - 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

        Function initTables has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def initTables(self):  # this function prepares the default settings for each table
                # hosts table (left)
                headers = ["Id", "OS", "Accuracy", "Host", "IPv4", "IPv6", "Mac", "Status", "Hostname", "Vendor", "Uptime",
                           "Lastboot", "Distance", "CheckedHost", "Country Code", "State", "City", "Latitude", "Longitude",
                           "Count", "Closed"]
        Severity: Minor
        Found in ui/view.py - About 1 hr to fix

          Function start has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def start(self, title='*untitled'):
                  self.viewState = ViewState()
                  self.ui.keywordTextInput.setText('')                            # clear keyword filter
          
                  self.ProcessesTableModel = None  # fixes bug when sorting processes for the first time
          Severity: Minor
          Found in ui/view.py - About 1 hr to fix

            Function updateToolsTableView has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def updateToolsTableView(self):
                    if self.ui.MainTabWidget.tabText(self.ui.MainTabWidget.currentIndex()) == 'Scan' and \
                            self.ui.HostsTabWidget.tabText(self.ui.HostsTabWidget.currentIndex()) == 'Tools':
                        self.ToolsTableModel.setDataList(
                            self.controller.getProcessesFromDB(self.viewState.filters,
            Severity: Minor
            Found in ui/view.py - 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

            Function createNewTabForHost has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def createNewTabForHost(self, ip, tabTitle, restoring=False, content='', filename=''):
                    # TODO: use regex otherwise tools with 'screenshot' in the name are screwed.
                    if 'screenshot' in str(tabTitle):
                        tempWidget = ImageViewer()
                        tempWidget.setObjectName(str(tabTitle))
            Severity: Minor
            Found in ui/view.py - 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

            Function callHydra has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def callHydra(self, bWidget):
                    if validateNmapInput(bWidget.ipTextinput.text()) and validateNmapInput(bWidget.portTextinput.text()):
                                                                                    # check if host is already in scope
                        if not self.controller.isHostInDB(bWidget.ipTextinput.text()):
                            message = "This host is not in scope. Add it to scope and continue?"
            Severity: Minor
            Found in ui/view.py - 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

            Function restoreToolTabWidget has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def restoreToolTabWidget(self, clear=False):
                    if self.ui.DisplayWidget.findChild(QtWidgets.QPlainTextEdit) == self.ui.toolOutputTextView:
                        return
                    
                    for host in self.viewState.hostTabs.keys():
            Severity: Minor
            Found in ui/view.py - 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

            Avoid deeply nested control flow statements.
            Open

                                   if len(nmapOptionValueSplit) > 1:
                                       nmapOptionValue = nmapOptionValueSplit[1].replace(']','')
                                       nmapOptions.append(nmapOptionValue)
                            nmapOptions.append(str(self.adddialog.txtCustomOptList.text()))
            Severity: Major
            Found in ui/view.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if host in targets:
                                          targets.remove(host)
                              
              Severity: Major
              Found in ui/view.py - About 45 mins to fix

                Function restoreToolTabsForHost has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def restoreToolTabsForHost(self, ip):
                        if (self.viewState.hostTabs) and (ip in self.viewState.hostTabs):
                            tabs = self.viewState.hostTabs[ip]    # use the ip as a key to retrieve its list of tooltabs
                            for tab in tabs:
                                # do not display hydra and nmap tabs when restoring for that host
                Severity: Minor
                Found in ui/view.py - About 45 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

                Function restoreToolTabs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def restoreToolTabs(self):
                        # false means we are fetching processes with display flag=False, which is the case for every process once
                        # a project is closed.
                        tools = self.controller.getProcessesFromDB(self.viewState.filters, showProcesses=False)
                        nbr = len(tools)  # show a progress bar because this could take long
                Severity: Minor
                Found in ui/view.py - About 45 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

                Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def __init__(self, viewState: ViewState, ui, ui_mainwindow, shell: Shell, app, loop):
                Severity: Minor
                Found in ui/view.py - About 45 mins to fix

                  Function createNewTabForHost has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def createNewTabForHost(self, ip, tabTitle, restoring=False, content='', filename=''):
                  Severity: Minor
                  Found in ui/view.py - About 35 mins to fix

                    Function contextMenuProcessesTableView has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def contextMenuProcessesTableView(self, pos):
                            if self.ui.ProcessesTableView.selectionModel() and self.ui.ProcessesTableView.selectionModel().selectedRows():
                        
                                menu = self.controller.getContextMenuForProcess()
                                menu.aboutToShow.connect(self.setVisible)
                    Severity: Minor
                    Found in ui/view.py - About 25 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

                    There are no issues that match your filters.

                    Category
                    Status