nypublicradio/ember-hifi

View on GitHub

Showing 20 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

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

                          if (this.hifiConnections.includes('HLS')) {
                            target.import({
                              development: 'vendor/third-party/hls.js',
                              production: 'vendor/third-party/hls.min.js'
                            });
                      Severity: Minor
                      Found in index.js and 1 other location - About 50 mins to fix
                      index.js on lines 20..27

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

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

                          if (this.hifiConnections.includes('Howler')) {
                            target.import({
                              development: 'vendor/third-party/howler.js',
                              production: 'vendor/third-party/howler.min.js'
                            });
                      Severity: Minor
                      Found in index.js and 1 other location - About 50 mins to fix
                      index.js on lines 29..36

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

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

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

                        rewind(duration) {
                          assert('[ember-hifi] Nothing is playing.', this.get('currentSound'));
                          this.get('currentSound').rewind(duration);
                        },
                      Severity: Minor
                      Found in addon/services/hifi.js and 1 other location - About 35 mins to fix
                      addon/services/hifi.js on lines 352..355

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

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

                        fastForward(duration) {
                          assert('[ember-hifi] Nothing is playing.', this.get('currentSound'));
                          this.get('currentSound').fastForward(duration);
                        },
                      Severity: Minor
                      Found in addon/services/hifi.js and 1 other location - About 35 mins to fix
                      addon/services/hifi.js on lines 364..367

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

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