betagouv/service-national-universel

View on GitHub
app/src/scenes/missions/viewMobile.jsx

Summary

Maintainability
F
5 days
Test Coverage

Function ViewMobile has 400 lines of code (exceeds 200 allowed). Consider refactoring.
Open

export default function ViewMobile() {
  const [mission, setMission] = useState();
  const [modal, setModal] = useState(null);
  const [loading, setLoading] = useState(false);
  const [currentTab, setCurrentTab] = useState("mots");
Severity: Major
Found in app/src/scenes/missions/viewMobile.jsx - About 1 day to fix

    Function ViewMobile has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function ViewMobile() {
      const [mission, setMission] = useState();
      const [modal, setModal] = useState(null);
      const [loading, setLoading] = useState(false);
      const [currentTab, setCurrentTab] = useState("mots");
    Severity: Minor
    Found in app/src/scenes/missions/viewMobile.jsx - About 1 day 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 ApplicationStatus has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    const ApplicationStatus = ({ mission, updateApplication, loading, setLoading, contract, contractHasAllValidation }) => {
      const young = useSelector((state) => state.Auth.young);
      const tutor = mission?.tutor;
      const application = mission?.application;
    
    
    Severity: Minor
    Found in app/src/scenes/missions/viewMobile.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

    File viewMobile.jsx has 729 lines of code (exceeds 700 allowed). Consider refactoring.
    Open

    import React, { useEffect, useRef, useState } from "react";
    import { AiFillClockCircle, AiOutlineClockCircle } from "react-icons/ai";
    import { BsChevronDown } from "react-icons/bs";
    import { HiChevronDown, HiOutlineMail, HiPlus } from "react-icons/hi";
    import { IoMdInformationCircleOutline } from "react-icons/io";
    Severity: Major
    Found in app/src/scenes/missions/viewMobile.jsx - About 2 hrs to fix

      Function InfoStructure has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      const InfoStructure = ({ title, structure }) => {
        const [value, setValue] = useState();
        const [expandNote, setExpandNote] = useState(false);
        useEffect(() => {
          (async () => {
      Severity: Minor
      Found in app/src/scenes/missions/viewMobile.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

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

      const SendContractByMail = ({ young, contractId, missionName }) => {
        const [modalMail, setModalMail] = useState({ isOpen: false, onConfirm: null });
      
        const onConfirm = async () => {
          try {
      Severity: Major
      Found in app/src/scenes/missions/viewMobile.jsx and 1 other location - About 7 hrs to fix
      app/src/scenes/missions/viewDesktop.jsx on lines 688..731

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

      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

                    <ModalPJ
                      isOpen={modalDocument?.isOpen}
                      name={modalDocument?.name}
                      young={young}
                      application={mission.application}
      Severity: Major
      Found in app/src/scenes/missions/viewMobile.jsx and 1 other location - About 6 hrs to fix
      app/src/scenes/missions/viewDesktop.jsx on lines 411..438

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

      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

        const handleClick = async () => {
          try {
            if (mission.isMilitaryPreparation === "true") {
              if (!["VALIDATED", "WAITING_VERIFICATION", "WAITING_CORRECTION", "REFUSED"].includes(young.statusMilitaryPreparationFiles)) {
                const responseChangeStatsPM = await api.put(`/young/${young._id}/phase2/militaryPreparation/status`, {
      Severity: Major
      Found in app/src/scenes/missions/viewMobile.jsx and 1 other location - About 3 hrs to fix
      app/src/scenes/missions/viewDesktop.jsx on lines 576..597

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

      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

        const updateApplication = async (status) => {
          setLoading(true);
          const { ok } = await api.put(`/application`, { _id: mission.application._id, status, ...(APPLICATION_STATUS.ABANDON === status ? { missionDuration: "0" } : {}) });
          if (!ok) toastr.error("Une erreur s'est produite lors de la mise à jour de  votre candidature");
          let template;
      Severity: Major
      Found in app/src/scenes/missions/viewMobile.jsx and 1 other location - About 2 hrs to fix
      app/src/scenes/missions/viewDesktop.jsx on lines 104..116

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

      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="relative" ref={refContractButton}>
                    <button
                      disabled={loading}
                      className="flex w-full items-center justify-between gap-3 rounded-full border-[1px] border-blue-600 bg-blue-600 px-3 py-2 disabled:cursor-wait disabled:opacity-50"
                      onClick={() => setOpenContractButton((e) => !e)}>
      Severity: Minor
      Found in app/src/scenes/missions/viewMobile.jsx and 1 other location - About 35 mins to fix
      app/src/scenes/missions/viewDesktop.jsx on lines 210..240

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

      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