TryGhost/Ghost

View on GitHub
apps/portal/src/components/common/ProductsSection.js

Summary

Maintainability
F
6 days
Test Coverage

File ProductsSection.js has 976 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React, {useContext, useEffect, useState} from 'react';
import {ReactComponent as LoaderIcon} from '../../images/icons/loader.svg';
import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.svg';
import {getCurrencySymbol, getPriceString, getStripeAmount, getMemberActivePrice, getProductFromPrice, getFreeTierTitle, getFreeTierDescription, getFreeProduct, getFreeProductBenefits, getSupportAddress, formatNumber, isCookiesDisabled, hasOnlyFreeProduct, isMemberActivePrice, hasFreeTrialTier, isComplimentaryMember} from '../../utils/helpers';
import AppContext from '../../AppContext';
Severity: Major
Found in apps/portal/src/components/common/ProductsSection.js - About 2 days to fix

    Function ProductsSectionStyles has 436 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const ProductsSectionStyles = () => {
        // const products = getSiteProducts({site});
        // const noOfProducts = products.length;
        return `
            .gh-portal-products {
    Severity: Major
    Found in apps/portal/src/components/common/ProductsSection.js - About 2 days to fix

      Function FreeProductCard has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      function FreeProductCard({products, handleChooseSignup, error}) {
          const {site, action, t} = useContext(AppContext);
          const {selectedProduct, setSelectedProduct} = useContext(ProductsContext);
      
          let cardClass = selectedProduct === 'free' ? 'gh-portal-product-card free checked' : 'gh-portal-product-card free';
      Severity: Minor
      Found in apps/portal/src/components/common/ProductsSection.js - 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

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

      function ProductCardPrice({product}) {
          const {selectedInterval} = useContext(ProductsContext);
          const {site} = useContext(AppContext);
          const monthlyPrice = product.monthlyPrice;
          const yearlyPrice = product.yearlyPrice;
      Severity: Minor
      Found in apps/portal/src/components/common/ProductsSection.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 ProductsSection has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      function ProductsSection({onPlanSelect, products, type = null, handleChooseSignup, errors}) {
          const {site, member, t} = useContext(AppContext);
          const {portal_plans: portalPlans, portal_default_plan: portalDefaultPlan} = site;
          const defaultProductId = products.length > 0 ? products[0].id : 'free';
      
      
      Severity: Minor
      Found in apps/portal/src/components/common/ProductsSection.js - About 45 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

      Function getActiveInterval has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function getActiveInterval({portalPlans, portalDefaultPlan, selectedInterval}) {
          if (selectedInterval === 'month' && portalPlans.includes('monthly')) {
              return 'month';
          }
      
      
      Severity: Minor
      Found in apps/portal/src/components/common/ProductsSection.js - About 35 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

      Avoid too many return statements within this function.
      Open

              return 'month';
      Severity: Major
      Found in apps/portal/src/components/common/ProductsSection.js - About 30 mins to fix

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

        function getSelectedPrice({products, selectedProduct, selectedInterval}) {
            let selectedPrice = null;
            if (selectedProduct === 'free') {
                selectedPrice = {id: 'free'};
            } else {
        Severity: Minor
        Found in apps/portal/src/components/common/ProductsSection.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

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

        function ProductCard({product, products, selectedInterval, handleChooseSignup, error}) {
            const {selectedProduct, setSelectedProduct} = useContext(ProductsContext);
            const {action} = useContext(AppContext);
            const trialDays = product.trial_days;
        
        
        Severity: Minor
        Found in apps/portal/src/components/common/ProductsSection.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

                                <div className="gh-portal-product-price">
                                    <span className={'currency-sign' + (currencySymbol.length > 1 ? ' long' : '')}>{currencySymbol}</span>
                                    <span className="amount" data-testid="product-amount">{formatNumber(getStripeAmount(activePrice.amount))}</span>
                                    <span className="billing-period">/{activePrice.interval}</span>
                                </div>
        Severity: Major
        Found in apps/portal/src/components/common/ProductsSection.js and 1 other location - About 4 hrs to fix
        apps/portal/src/components/common/ProductsSection.js on lines 633..637

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

        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="gh-portal-product-price">
                            <span className={'currency-sign' + (currencySymbol.length > 1 ? ' long' : '')}>{currencySymbol}</span>
                            <span className="amount" data-testid="product-amount">{formatNumber(getStripeAmount(activePrice.amount))}</span>
                            <span className="billing-period">/{activePrice.interval}</span>
                        </div>
        Severity: Major
        Found in apps/portal/src/components/common/ProductsSection.js and 1 other location - About 4 hrs to fix
        apps/portal/src/components/common/ProductsSection.js on lines 615..619

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

        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='gh-portal-product-card-header'>
                            <h4 className="gh-portal-product-name">{product.name}</h4>
                            <ProductCardPrice product={product} />
                        </div>
        Severity: Major
        Found in apps/portal/src/components/common/ProductsSection.js and 1 other location - About 1 hr to fix
        apps/portal/src/components/common/ProductsSection.js on lines 1095..1098

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

        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='gh-portal-product-card-header'>
                        <h4 className="gh-portal-product-name">{product.name}</h4>
                        <ProductCardPrice product={product} />
                    </div>
        Severity: Major
        Found in apps/portal/src/components/common/ProductsSection.js and 1 other location - About 1 hr to fix
        apps/portal/src/components/common/ProductsSection.js on lines 778..781

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

        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
                            data-test-button='switch-yearly'
                            data-testid="yearly-switch"
                            className={'gh-portal-btn' + (selectedInterval === 'year' ? ' active' : '')}
                            onClick={() => {
        Severity: Major
        Found in apps/portal/src/components/common/ProductsSection.js and 1 other location - About 1 hr to fix
        apps/portal/src/components/common/ProductsSection.js on lines 873..882

        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

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

                        <button
                            data-test-button='switch-monthly'
                            data-testid="monthly-switch"
                            className={'gh-portal-btn' + (selectedInterval === 'month' ? ' active' : '')}
                            onClick={() => {
        Severity: Major
        Found in apps/portal/src/components/common/ProductsSection.js and 1 other location - About 1 hr to fix
        apps/portal/src/components/common/ProductsSection.js on lines 883..893

        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

        There are no issues that match your filters.

        Category
        Status