betagouv/service-national-universel

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

Summary

Maintainability
F
5 days
Test Coverage

Function ViewDesktop has 392 lines of code (exceeds 200 allowed). Consider refactoring.
Open

export default function ViewDesktop() {
  const [mission, setMission] = useState();
  const [modal, setModal] = useState(null);
  const [loading, setLoading] = useState(false);
  const [contract, setContract] = useState(null);
Severity: Major
Found in app/src/scenes/missions/viewDesktop.jsx - About 1 day to fix

    Function ViewDesktop has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function ViewDesktop() {
      const [mission, setMission] = useState();
      const [modal, setModal] = useState(null);
      const [loading, setLoading] = useState(false);
      const [contract, setContract] = useState(null);
    Severity: Minor
    Found in app/src/scenes/missions/viewDesktop.jsx - About 7 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 ApplicationStatus has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    const ApplicationStatus = ({ mission, updateApplication, loading }) => {
      const young = useSelector((state) => state.Auth.young);
      const [cancelModal, setCancelModal] = React.useState({ isOpen: false, onConfirm: null });
      const application = mission?.application;
      const tutor = mission?.tutor;
    Severity: Minor
    Found in app/src/scenes/missions/viewDesktop.jsx - About 4 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 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/viewDesktop.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/viewDesktop.jsx and 1 other location - About 7 hrs to fix
    app/src/scenes/missions/viewMobile.jsx on lines 727..770

    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/viewDesktop.jsx and 1 other location - About 6 hrs to fix
    app/src/scenes/missions/viewMobile.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

                  onClick={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/viewDesktop.jsx and 1 other location - About 3 hrs to fix
    app/src/scenes/missions/viewMobile.jsx on lines 495..516

    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/viewDesktop.jsx and 1 other location - About 2 hrs to fix
    app/src/scenes/missions/viewMobile.jsx on lines 100..112

    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 w-1/6" 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 hover:border-blue-500 hover:bg-blue-500 disabled:cursor-wait disabled:opacity-50"
                      onClick={() => setOpenContractButton((e) => !e)}>
    Severity: Minor
    Found in app/src/scenes/missions/viewDesktop.jsx and 1 other location - About 35 mins to fix
    app/src/scenes/missions/viewMobile.jsx on lines 534..564

    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