glitch-soc/mastodon

View on GitHub
app/javascript/flavours/glitch/components/media_gallery.jsx

Summary

Maintainability
F
1 wk
Test Coverage

Function render has 99 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  render () {
    const { attachment, lang, index, size, standalone, letterbox, displayWidth, visible } = this.props;

    let badges = [], thumbnail;

Severity: Major
Found in app/javascript/flavours/glitch/components/media_gallery.jsx - About 3 hrs to fix

    File media_gallery.jsx has 303 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import PropTypes from 'prop-types';
    import { PureComponent } from 'react';
    
    import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
    
    
    Severity: Minor
    Found in app/javascript/flavours/glitch/components/media_gallery.jsx - About 3 hrs to fix

      Function render has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

        render () {
          const { attachment, lang, index, size, standalone, letterbox, displayWidth, visible } = this.props;
      
          let badges = [], thumbnail;
      
      
      Severity: Minor
      Found in app/javascript/flavours/glitch/components/media_gallery.jsx - About 3 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 render has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        render () {
          const { media, lang, intl, sensitive, letterbox, fullwidth, defaultWidth, autoplay } = this.props;
          const { visible } = this.state;
          const size     = media.take(4).size;
          const uncached = media.every(attachment => attachment.get('type') === 'unknown');
      Severity: Minor
      Found in app/javascript/flavours/glitch/components/media_gallery.jsx - About 1 hr to fix

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

          render () {
            const { media, lang, intl, sensitive, letterbox, fullwidth, defaultWidth, autoplay } = this.props;
            const { visible } = this.state;
            const size     = media.take(4).size;
            const uncached = media.every(attachment => attachment.get('type') === 'unknown');
        Severity: Minor
        Found in app/javascript/flavours/glitch/components/media_gallery.jsx - 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

        Consider simplifying this complex logical expression.
        Open

            } else if (attachment.get('type') === 'image') {
              const previewUrl   = attachment.get('preview_url');
              const previewWidth = attachment.getIn(['meta', 'small', 'width']);
        
              const originalUrl   = attachment.get('url');
        Severity: Major
        Found in app/javascript/flavours/glitch/components/media_gallery.jsx - About 40 mins to fix

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

              if (uncached) {
                spoilerButton = (
                  <button type='button' disabled className='spoiler-button__overlay'>
                    <span className='spoiler-button__overlay__label'>
                      <FormattedMessage id='status.uncached_media_warning' defaultMessage='Preview not available' />
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 1 day to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 317..337

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

          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 (attachment.get('type') === 'unknown') {
                return (
                  <div className={classNames('media-gallery__item', { standalone, 'media-gallery__item--tall': height === 100, 'media-gallery__item--wide': width === 100 })} key={attachment.get('id')}>
                    <a className='media-gallery__item-thumbnail' href={attachment.get('remote_url') || attachment.get('url')} style={{ cursor: 'pointer' }} title={description} lang={lang} target='_blank' rel='noopener noreferrer'>
                      <Blurhash
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 7 hrs to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 111..184

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

          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

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

            UNSAFE_componentWillReceiveProps (nextProps) {
              if (!is(nextProps.media, this.props.media) && nextProps.visible === undefined) {
                this.setState({ visible: displayMedia !== 'hide_all' && !nextProps.sensitive || displayMedia === 'show_all' });
              } else if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {
                this.setState({ visible: nextProps.visible });
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 5 hrs to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 239..245

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

          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

            handleClick = (e) => {
              const { index, onClick } = this.props;
          
              if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
                if (this.hoverToPlay()) {
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 5 hrs to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 70..83

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

          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

                <div className={classNames('media-gallery__item', { standalone, letterbox, 'media-gallery__item--tall': height === 100, 'media-gallery__item--wide': width === 100 })} key={attachment.get('id')}>
                  <Blurhash
                    hash={attachment.get('blurhash')}
                    dummy={!useBlurhash}
                    className={classNames('media-gallery__preview', {
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 3 hrs to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 187..203

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

          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

            state = {
              visible: this.props.visible !== undefined ? this.props.visible : (displayMedia !== 'hide_all' && !this.props.sensitive || displayMedia === 'show_all'),
              width: this.props.defaultWidth,
            };
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 2 hrs to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 226..229

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

          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

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

              if (this.isStandaloneEligible()) {
                children = <Item standalone autoplay={autoplay} onClick={this.handleClick} attachment={media.get(0)} lang={lang} displayWidth={width} visible={visible} />;
              } else {
                children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} autoplay={autoplay} onClick={this.handleClick} attachment={attachment} index={i} lang={lang} size={size} letterbox={letterbox} displayWidth={width} visible={visible || uncached} />);
              }
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 1 hr to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 311..315

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

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

            handleOpen = () => {
              if (this.props.onToggleVisibility) {
                this.props.onToggleVisibility();
              } else {
                this.setState({ visible: !this.state.visible });
          app/javascript/flavours/glitch/features/audio/index.jsx on lines 229..235
          app/javascript/mastodon/components/media_gallery.jsx on lines 255..261
          app/javascript/mastodon/features/audio/index.jsx on lines 223..229
          app/javascript/mastodon/features/video/index.jsx on lines 468..474

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

          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

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

              if (attachment.get('description')?.length > 0) {
                badges.push(<span key='alt' className='media-gallery__alt__label'>ALT</span>);
              }
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 1 hr to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 105..107

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

          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

          Identical blocks of code found in 4 locations. Consider refactoring.
          Open

            handleMouseLeave = (e) => {
              if (this.hoverToPlay()) {
                e.target.pause();
                e.target.currentTime = 0;
              }
          Severity: Major
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 3 other locations - About 55 mins to fix
          app/javascript/flavours/glitch/features/account_gallery/components/media_item.jsx on lines 38..43
          app/javascript/mastodon/components/media_gallery.jsx on lines 54..59
          app/javascript/mastodon/features/account_gallery/components/media_item.jsx on lines 38..43

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

          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

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

            hoverToPlay () {
              const { attachment } = this.props;
              return !this.getAutoPlay() && attachment.get('type') === 'gifv';
            }
          Severity: Minor
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 55 mins to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 65..68

          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

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

                <div className={computedClass} style={style} ref={this.handleRef}>
                  <div className={classNames('spoiler-button', { 'spoiler-button--minified': visible && !uncached, 'spoiler-button--click-thru': uncached })}>
                    {spoilerButton}
                  </div>
          
          
          Severity: Minor
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 50 mins to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 340..346

          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

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

                  <a
                    className='media-gallery__item-thumbnail'
                    href={attachment.get('remote_url') || originalUrl}
                    onClick={this.handleClick}
                    target='_blank'
          Severity: Minor
          Found in app/javascript/flavours/glitch/components/media_gallery.jsx and 1 other location - About 45 mins to fix
          app/javascript/mastodon/components/media_gallery.jsx on lines 141..158

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

          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

          There are no issues that match your filters.

          Category
          Status