krateng/maloja

View on GitHub

Showing 192 of 192 total issues

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

        else if (this.status == 403) {
            //document.getElementById("checkmark_url").innerHTML = "✔️"
            //document.getElementById("checkmark_key").innerHTML = "❌"
            document.getElementById("serverurl").style.backgroundColor = "lawngreen"
            document.getElementById("apikey").style.backgroundColor = "red"
Severity: Minor
Found in auxiliary/chromium_scrobbler/maloja-scrobbler/settings.js and 1 other location - About 55 mins to fix
auxiliary/chromium_scrobbler/maloja-scrobbler/settings.js on lines 130..147

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

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

Function get_scrobbles_of_track has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

def get_scrobbles_of_track(track,since=None,to=None,resolve_references=True,limit=None,reverse=False,dbconn=None):
Severity: Major
Found in maloja/database/sqldb.py - About 50 mins to fix

    Function get_scrobbles_of_album has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def get_scrobbles_of_album(album,since=None,to=None,resolve_references=True,limit=None,reverse=False,dbconn=None):
    Severity: Major
    Found in maloja/database/sqldb.py - About 50 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if duration in ('-',''): duration = None
                          scrobblelist.append({
      Severity: Major
      Found in maloja/upgrade.py - About 45 mins to fix

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

        def set_image(b64,**keys):
            if "title" in keys:
                entity = {"track":keys}
                id = database.sqldb.get_track_id(entity['track'])
                idkeys = {'track_id':id}
        Severity: Minor
        Found in maloja/images.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

        Avoid deeply nested control flow statements.
        Open

                            if album_id:
                                result['value'] = placeholder_url + f"joy-division&colors={album_id % 100}"
                        else:
        Severity: Major
        Found in maloja/images.py - About 45 mins to fix

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

          def count_scrobbles_by_album_combined(since,to,artist,associated=False,resolve_ids=True,dbconn=None):
          Severity: Minor
          Found in maloja/database/sqldb.py - About 45 mins to fix

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

            def add_common_args_to_docstring(filterkeys=False,limitkeys=False,delimitkeys=False,amountkeys=False):
                def decorator(func):
                    timeformats = "Possible formats include '2022', '2022/08', '2022/08/01', '2022/W42', 'today', 'thismonth', 'monday', 'august'"
            
                    if filterkeys:
            Severity: Minor
            Found in maloja/apis/native_v1.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 count_scrobbles_by_track_of_artist has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def count_scrobbles_by_track_of_artist(since,to,artist,associated=False,resolve_ids=True,dbconn=None):
            Severity: Minor
            Found in maloja/database/sqldb.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (result["service_active_" + key]) {
                                          console.log("New page on tab " + tabId + " will be handled by new " + key + " manager!");
                                          tabManagers[tabId] = new Controller(tabId,key);
                                          updateTabNum();
                                          //chrome.tabs.executeScript(tab.id,{"file":"sitescripts/" + pages[key]["script"]})
              Severity: Major
              Found in auxiliary/chromium_scrobbler/maloja-scrobbler/background.js - About 45 mins to fix

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

                    def next(self,step=1):
                        if abs(step) == math.inf: return None
                        if self.precision == 1:
                            return MTRangeGregorian(self.year + step)
                        elif self.precision == 2:
                Severity: Minor
                Found in maloja/malojatime.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 stop has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def stop():
                
                    for attempt in [(signal.SIGTERM,2),(signal.SIGTERM,5),(signal.SIGKILL,3),(signal.SIGKILL,5)]:
                
                        pid_sv = get_instance_supervisor()
                Severity: Minor
                Found in maloja/__main__.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

                Avoid deeply nested control flow statements.
                Open

                                    if artist_id:
                                        result['value'] = placeholder_url + f"tiles&colors={artist_id % 100}"
                                    if track_id:
                Severity: Major
                Found in maloja/images.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if track_id:
                                          result['value'] = "/static/svg/placeholder_track.svg"
                                      if album_id:
                  Severity: Major
                  Found in maloja/images.py - About 45 mins to fix

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

                    def count_scrobbles_by_album_of_artist(since,to,artist,associated=False,resolve_ids=True,dbconn=None):
                    Severity: Minor
                    Found in maloja/database/sqldb.py - About 45 mins to fix

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

                      def count_scrobbles_of_artist_by_album(since,to,artist,associated=False,resolve_ids=True,dbconn=None):
                      Severity: Minor
                      Found in maloja/database/sqldb.py - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                            if track_id:
                                                result['value'] = placeholder_url + f"triangles&colors={track_id % 100}"
                                            if album_id:
                        Severity: Major
                        Found in maloja/images.py - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                              if artist_id:
                                                  result['value'] = "/static/svg/placeholder_artist.svg"
                                              if track_id:
                          Severity: Major
                          Found in maloja/images.py - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                    if (abs(scr[0] - timestamp) < 30) and scr[1:] == scrobble_describe[1:]:
                                                        yield ('UNCERTAIN_SKIP',None,f"{entry} might be a duplicate, skipping...")
                                                        found_similar = True
                                                        break
                                                else:
                            Severity: Major
                            Found in maloja/proccontrol/tasks/import_scrobbles.py - About 45 mins to fix

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

                                  def handshake(self,pathnodes,keys):
                                      auth = keys.get("a")
                                      timestamp = keys.get("t")
                                      apikey = keys.get("api_key")
                                      host = keys.get("Host")
                              Severity: Minor
                              Found in maloja/apis/audioscrobbler_legacy.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

                              Severity
                              Category
                              Status
                              Source
                              Language