nypublicradio/ember-hifi

View on GitHub

Showing 16 of 20 total issues

File hifi.js has 424 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { or, readOnly, equal, reads, alias } from '@ember/object/computed';
import { later, cancel } from '@ember/runloop';
import { isEmpty } from '@ember/utils';
import { assign } from '@ember/polyfills';
import { getOwner } from '@ember/application';
Severity: Minor
Found in addon/services/hifi.js - About 6 hrs to fix

    `` has 36 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default Service.extend(Evented, DebugLogging, {
      debugName: 'ember-hifi',
      poll:              service(),
      soundCache:        service('hifi-cache'),
      isMobileDevice:    computed({
    Severity: Minor
    Found in addon/services/hifi.js - About 4 hrs to fix

      Sound has 28 functions (exceeds 20 allowed). Consider refactoring.
      Open

      let Sound = BaseSound.extend({
        setup() {
          let audio = this.requestControl();
      
          audio.src = this.get('url');
      Severity: Minor
      Found in addon/hifi-connections/native-audio.js - About 3 hrs to fix

        Function load has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          load(urlsOrPromise, options) {
            let sharedAudioAccess = this._createAndUnlockAudio();
        
            options = assign({
              debugName: `load-${Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 3)}`,
        Severity: Major
        Found in addon/services/hifi.js - About 2 hrs to fix

          File native-audio.js has 267 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import { A } from '@ember/array';
          import { run } from '@ember/runloop';
          import Mixin from '@ember/object/mixin';
          import BaseSound from './base';
          import Ember from 'ember';
          Severity: Minor
          Found in addon/hifi-connections/native-audio.js - About 2 hrs to fix

            Function init has 58 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              init: function() {
                let {
                  audioLoading,
                  audioLoaded,
                  audioReady,
            Severity: Major
            Found in addon/hifi-connections/base.js - About 2 hrs to fix

              Function load has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
              Open

                load(urlsOrPromise, options) {
                  let sharedAudioAccess = this._createAndUnlockAudio();
              
                  options = assign({
                    debugName: `load-${Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 3)}`,
              Severity: Minor
              Found in addon/services/hifi.js - 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 getInfoFromUrl has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                getInfoFromUrl: function() {
                  if (!this.get('url')) {
                    return {};
                  }
                  else if (this.get('url').startsWith('/')) {
              Severity: Minor
              Found in addon/hifi-connections/dummy-connection.js - 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 promise has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  let promise = new RSVP.Promise((resolve, reject) => {
                    return this._resolveUrls(urlsOrPromise).then(urlsToTry => {
                      if (isEmpty(urlsToTry)) {
                        return reject(new Error('[ember-hifi] URLs must be provided'));
                      }
              Severity: Minor
              Found in addon/services/hifi.js - About 1 hr to fix

                Function _handleAudioEvent has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _handleAudioEvent(eventName, e) {
                    if (!this.urlsAreEqual(e.target.src, this.get('url')) && e.target.src !== '') {
                      // This event is not for us if our srcs aren't equal
                
                      // but if the target src is empty it means we've been stopped and in
                Severity: Minor
                Found in addon/hifi-connections/native-audio.js - About 1 hr to fix

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

                    setup() {
                      let urls = makeArray(this.get('url'));
                      let sound = this;
                      let options = Object.assign({
                        src:      urls,
                  Severity: Minor
                  Found in addon/hifi-connections/howler.js - About 1 hr to fix

                    Function _setupHLSEvents has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      _setupHLSEvents(hls) {
                        hls.on(HLS.Events.MEDIA_ATTACHED, () => {
                          this.debug('media attached');
                          hls.loadSource(this.get('url'));
                    
                    
                    Severity: Minor
                    Found in addon/hifi-connections/hls.js - About 1 hr to fix

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

                        requestControl(who) {
                          let owner = this.get('owner');
                      
                          if ((owner !== who) && owner) {
                            who.debug("I need audio control");
                      Severity: Minor
                      Found in addon/utils/shared-audio-access.js - 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 restoreState has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        restoreState() {
                          let sharedElement     = this.audioElement();
                          let internalElement   = this.get('_audioElement');
                      
                          if (this.get('sharedAudioAccess') && internalElement) {
                      Severity: Minor
                      Found in addon/hifi-connections/native-audio.js - About 35 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 canPlay has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        canPlay(url) {
                          let usablePlatform = this.canUseConnection(url);
                          if (!usablePlatform) {
                            return false;
                          }
                      Severity: Minor
                      Found in addon/hifi-connections/base.js - About 35 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 log has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        log(content) {
                          if (window.console && window.console.log) {
                            const colorString = `color: ${this.color}; font-weight: bold;`;
                            const name = this.name.slice(0, this.padLength);
                            const titleContent = Array(this.padLength + 3 - name.length).join(' ');
                      Severity: Minor
                      Found in addon/utils/debug.js - 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

                      Severity
                      Category
                      Status
                      Source
                      Language