atlp-rwanda/hackers-ec-Fe

View on GitHub
src/pages/SingleProduct.tsx

Summary

Maintainability
F
4 days
Test Coverage
C
76%

Function SingleProduct has 245 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const SingleProduct = () => {
    const { isLoading, singleProduct } = useAppSelector((state) => state.product);

    const dispatch = useAppDispatch();
    const review = useAppSelector(
Severity: Major
Found in src/pages/SingleProduct.tsx - About 1 day to fix

    Function SingleProduct has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    const SingleProduct = () => {
        const { isLoading, singleProduct } = useAppSelector((state) => state.product);
    
        const dispatch = useAppDispatch();
        const review = useAppSelector(
    Severity: Minor
    Found in src/pages/SingleProduct.tsx - 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

    File SingleProduct.tsx has 272 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    //import { FaCartPlus, FaPlus, FaMinus } from 'react-icons/fa';
    import { useAppDispatch, useAppSelector } from '../redux/hooks/hooks';
    import { useEffect, useState } from 'react';
    import { IoMdArrowDropdown } from 'react-icons/io';
    import { IoChevronBackSharp } from 'react-icons/io5';
    Severity: Minor
    Found in src/pages/SingleProduct.tsx - About 2 hrs to fix

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

                                              review.slice(0, 2).map((item: DynamicData) => (
                                                  <div
                                                      className="single-review mt-4 border-t   pt-4  border-inputCaption flex  flex-col gap-3 ipad:flex-ow ipad:gap11 ipad:justify-between "
                                                      key={item.id}
                                                  >
      Severity: Major
      Found in src/pages/SingleProduct.tsx and 1 other location - About 1 day to fix
      src/components/product/review/AllReview.tsx on lines 148..178

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

      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 hover:cursor-pointer"
                                                      onMouseEnter={() => setRatingTab(true)}
                                                      onMouseLeave={() => setRatingTab(false)}
                                                  >
      Severity: Major
      Found in src/pages/SingleProduct.tsx and 1 other location - About 3 hrs to fix
      src/components/product/review/AllReview.tsx on lines 114..127

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

      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

                                          <Slider {...settings}>
                                              {singleProduct[0]?.images?.map(
                                                  (item: string, index: number) => (
                                                      <ProductImageCard key={index} image={item} idx={0} />
                                                  ),
      Severity: Major
      Found in src/pages/SingleProduct.tsx and 1 other location - About 2 hrs to fix
      src/pages/dashboard/seller/SellerSingleProduct.tsx on lines 101..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 75.

      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

                                              <button
                                                  className="bg-custom-gradient w-[11rem]  hover:scale-105  text-neutral-white text-center py-[2%]  rounded  text-[12px] mobile:w-[90%] ipad:max-w-[11rem] mobile:px-2"
                                                  onClick={() => handleReviewForm()}
                                                  data-testid="first-button-submit-review"
                                              >
      Severity: Major
      Found in src/pages/SingleProduct.tsx and 1 other location - About 1 hr to fix
      src/components/product/review/AllReview.tsx on lines 134..142

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

      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

          const review = useAppSelector(
              (state) => state.fetchReview.data[state.fetchReview.data.length - 1]?.data,
          );
      Severity: Major
      Found in src/pages/SingleProduct.tsx and 4 other locations - About 35 mins to fix
      src/components/Forms/ReviewForm.tsx on lines 37..39
      src/components/product/review/AllReview.tsx on lines 24..26
      src/components/product/review/ratingModel.tsx on lines 6..8
      src/hooks/useWishlist.ts on lines 10..12

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

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

                                  <Link to={'/products'}>
                                      <ButtonIcon className="absolute py-1 mobile:py-2 -top-8 mobile:top-0 right-0 ipad:top-4 mobile:-right-20 mobile:px-6 ipad:px-8 ipad:right-4 bg-transparent bg-primary-lightblue text-neutral-white border-primary-lightblue border-2 ">
                                          <IoChevronBackSharp />
                                      </ButtonIcon>
                                  </Link>
      Severity: Minor
      Found in src/pages/SingleProduct.tsx and 2 other locations - About 30 mins to fix
      src/pages/dashboard/seller/Sales/SingleSale.tsx on lines 87..91
      src/pages/dashboard/seller/SellerSingleProduct.tsx on lines 154..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 45.

      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