nexxtway/react-rainbow

View on GitHub
src/components/TimePicker/timeSelect.js

Summary

Maintainability
F
5 days
Test Coverage

File timeSelect.js has 470 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable react/sort-comp */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ButtonIcon from '../ButtonIcon';
import AmPmSelect from './ampmSelect';
Severity: Minor
Found in src/components/TimePicker/timeSelect.js - About 7 hrs to fix

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

        render() {
            const { hour, minutes, ampm, inputFocusedIndex } = this.state;
            const { onCloseModal, cancelLabel, okLabel, hour24, className } = this.props;
            const hourPlaceholder = this.prevHour || '--';
            const minutesPlaceholder = this.prevMinutes || '--';
    Severity: Major
    Found in src/components/TimePicker/timeSelect.js - About 3 hrs to fix

      TimeSelect has 30 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export default class TimeSelect extends Component {
          constructor(props) {
              super(props);
              this.state = {
                  hour: getHour(props.value),
      Severity: Minor
      Found in src/components/TimePicker/timeSelect.js - About 3 hrs to fix

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

            handleChangeHour(event) {
                const { hour } = this.state;
                const { hour24 } = this.props;
                const { value } = event.target;
                let normalizedValue;
        Severity: Minor
        Found in src/components/TimePicker/timeSelect.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 constructor has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            constructor(props) {
                super(props);
                this.state = {
                    hour: getHour(props.value),
                    minutes: getMinutes(props.value),
        Severity: Minor
        Found in src/components/TimePicker/timeSelect.js - About 1 hr to fix

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

              handleChangeHour(event) {
                  const { hour } = this.state;
                  const { hour24 } = this.props;
                  const { value } = event.target;
                  let normalizedValue;
          Severity: Minor
          Found in src/components/TimePicker/timeSelect.js - About 1 hr to fix

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

                handleChangeMinutes(event) {
                    const { minutes } = this.state;
                    const { value } = event.target;
                    const { hour24 } = this.props;
                    let normalizedValue;
            Severity: Minor
            Found in src/components/TimePicker/timeSelect.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

            Consider simplifying this complex logical expression.
            Open

                    if (
                        (currentHour && currentMinutes && ampm && !hour24) ||
                        (currentHour && currentMinutes && hour24)
                    ) {
                        onChange(time);
            Severity: Major
            Found in src/components/TimePicker/timeSelect.js - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                      if (isNumber(value)) {
                          this.value = value;
                          if (Number(value) > 23 || this.isUpOrDownKeyPressed || this.hasPropValue) {
                              const newTypedValue = getSingleNewTypedValue(hour, value);
                              normalizedValue = normalizeHour(newTypedValue, hour24);
              Severity: Major
              Found in src/components/TimePicker/timeSelect.js - About 1 hr to fix

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

                    handleKeyDown(event) {
                        const { keyCode } = event;
                
                        if (keyCode === RIGHT_KEY) {
                            this.handleRightKeyPressed();
                Severity: Minor
                Found in src/components/TimePicker/timeSelect.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

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

                    incrementHandler() {
                        const { inputFocusedIndex } = this.state;
                        this.isUpOrDownKeyPressed = true;
                        if (inputFocusedIndex === 0) {
                            this.incrementHour();
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 3 hrs to fix
                src/components/TimePicker/timeSelect.js on lines 281..293

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

                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

                    decrementHandler() {
                        const { inputFocusedIndex } = this.state;
                        this.isUpOrDownKeyPressed = true;
                        if (inputFocusedIndex === 0) {
                            this.decrementHour();
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 3 hrs to fix
                src/components/TimePicker/timeSelect.js on lines 267..279

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

                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

                    incrementHour() {
                        const { hour } = this.state;
                        const { hour24 } = this.props;
                        const hourValue = hour || this.prevHour;
                        this.setState({
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 2 hrs to fix
                src/components/TimePicker/timeSelect.js on lines 346..353

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

                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

                    decrementHour() {
                        const { hour } = this.state;
                        const { hour24 } = this.props;
                        const hourValue = hour || this.prevHour;
                        this.setState({
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 2 hrs to fix
                src/components/TimePicker/timeSelect.js on lines 337..344

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

                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

                                        <ButtonIcon
                                            id="time-picker_up-button"
                                            tabIndex="-1"
                                            variant="border-filled"
                                            icon={<StyledUpArrow />}
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 2 hrs to fix
                src/components/TimePicker/timeSelect.js on lines 468..478

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

                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

                                        <ButtonIcon
                                            id="time-picker_down-button"
                                            tabIndex="-1"
                                            variant="border-filled"
                                            icon={<StyledDownArrow />}
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 2 hrs to fix
                src/components/TimePicker/timeSelect.js on lines 456..466

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

                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

                    handleFocusMinutes() {
                        const { minutes } = this.state;
                        this.prevMinutes = minutes || this.prevMinutes;
                        this.setState({
                            inputFocusedIndex: 1,
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 1 hr to fix
                src/components/TimePicker/timeSelect.js on lines 141..148

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

                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

                    handleFocusHour() {
                        const { hour } = this.state;
                        this.prevHour = hour || this.prevHour;
                        this.setState({
                            inputFocusedIndex: 0,
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 1 hr to fix
                src/components/TimePicker/timeSelect.js on lines 199..206

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

                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

                    incrementMinutes() {
                        const { minutes } = this.state;
                        const minutesValue = minutes || this.prevMinutes;
                        this.setState({
                            minutes: normalizeMinutes(getNextMinute(minutesValue)),
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 1 hr to fix
                src/components/TimePicker/timeSelect.js on lines 363..369

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

                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

                    decrementMinutes() {
                        const { minutes } = this.state;
                        const minutesValue = minutes || this.prevMinutes;
                        this.setState({
                            minutes: normalizeMinutes(getPrevMinute(minutesValue)),
                Severity: Major
                Found in src/components/TimePicker/timeSelect.js and 1 other location - About 1 hr to fix
                src/components/TimePicker/timeSelect.js on lines 355..361

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

                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