Showing 923 of 941 total issues
Function Step
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
const Step = () => {
const [data] = useContext(PreInscriptionContext);
const { step } = useParams();
const [isInscriptionOpen, setInscriptionOpen] = useState(false);
- Read upRead up
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 getYoungValidatedFromWaitingStatus
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
async function getYoungValidatedFromWaitingStatus(startDate, endDate, user) {
// ref dep && ref reg && admin
const token = await getAccessToken(config.API_ANALYTICS_ENDPOINT, config.API_ANALYTICS_API_KEY);
let body = {
startDate: formatDateForPostGre(startDate),
- Read upRead up
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 populateEtablissementWithNumber
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
const populateEtablissementWithNumber = async ({ etablissements, index }) => {
const etablissementIds = [...new Set(etablissements.map((item) => item._id.toString()).filter((e) => e))];
if (etablissementIds.length > 0) {
let body = {
query: {
- Read upRead up
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 aggregateStatus
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function aggregateStatus(youngs) {
let departments = {};
for (const young of youngs) {
if (departments[young.department] === undefined) {
departments[young.department] = {
- Read upRead up
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 checkPassword
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
async checkPassword(req, res) {
const { error, value } = Joi.object({
password: Joi.string().required(),
})
.unknown()
- Read upRead up
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 resetPassword
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
async resetPassword(req, res) {
const { error, value } = Joi.object({
password: Joi.string().required(),
newPassword: Joi.string().required(),
verifyPassword: Joi.string().required(),
- Read upRead up
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 buildMissionContext
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
async function buildMissionContext(user) {
const contextFilters = [];
// A young can only see validated missions.
if (isYoung(user)) contextFilters.push({ term: { "status.keyword": "VALIDATED" } });
- Read upRead up
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 Index
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export default function Index() {
const young = useSelector((state) => state.Auth.young);
const { isCLE } = useAuth();
const cohort = getCohort(young.cohort);
- Read upRead up
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 EmailForm
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export default function EmailForm({ referent, reinscription, invitationToken }: Props) {
const history = useHistory();
const { search } = useLocation();
const [email, setEmail] = useState(referent.email);
- Read upRead up
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 sendEmail
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export async function sendEmail(to: Email[], subject: string, htmlContent, { params, attachment, cc, bcc }: Omit<SendMailParameters, "emailTo"> = {}) {
try {
if (config.get("MAIL_TRANSPORT") === "SMTP") {
await sendMailCatcher(subject, htmlContent, { emailTo: to, cc, bcc, attachment });
return;
- Read upRead up
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 fetchDataForYoungCertificate
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export const fetchDataForYoungCertificate = async (young: YoungDto) => {
const session = await SessionPhase1Model.findById(young.sessionPhase1Id);
if (!session) throw new Error(`session ${young.sessionPhase1Id} not found for young ${young._id}`);
const center = await CohesionCenterModel.findById(session.cohesionCenterId);
if (!center) throw new Error(`center ${session.cohesionCenterId} not found for young ${young._id} - session ${session._id}`);
- Read upRead up
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 RoundButton
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function RoundButton({ children, className = "", onClick = () => {}, spinner = false, icon, href, target, rel, mode = "blue", disabled = false }) {
let color;
switch (mode) {
case "grey":
- Read upRead up
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 sendEmailToYoung
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export async function sendEmailToYoung(template: string, young, params: EmailParams = {}) {
const { cta, message, missionName, structureName, type_document, object, link } = params;
let buttonCta = cta || config.APP_URL;
if (template === SENDINBLUE_TEMPLATES.young.MILITARY_PREPARATION_DOCS_CORRECTION) buttonCta = `${config.APP_URL}/ma-preparation-militaire`;
if (template === SENDINBLUE_TEMPLATES.young.INSCRIPTION_STARTED)
- Read upRead up
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 compute
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
compute: async (_id, fromUser, options) => {
const YoungModel = options?.YoungModel; // Prevent circular dependency in YoungModel post save hook
if (!YoungModel) throw new Error("YoungModel is required");
let classe = await ClasseModel.findById(_id);
- Read upRead up
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 SelectCohort
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export default function SelectCohort({ cohort, withBadge, sort, filterFn, onChange, disabled, className, isSearchable }: Props) {
const cohorts = useSelector((state: CohortState) => state.Cohorts);
const [isSelectMenuOpen, setIsSelectMenuOpen] = useState(false);
- Read upRead up
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 PageButton
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function PageButton({ page, setCurrentPageNumber, active, lastPage, isLast = false }) {
const getClass = () => {
const classTab: string[] = [];
active ? classTab.push("font-bold bg-gray-100 text-gray-900") : classTab.push("font-normal"); // la page est active
page !== lastPage && !isLast ? classTab.push("border-r border-solid border-gray-200") : null; // page par defaut
- Read upRead up
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 Resum
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export default function Resum({ summary, cohort, addLigne }: Props) {
const cohorts = useSelector((state: CohortState) => state.Cohorts);
const currentCohort = cohorts.find((c) => c.name === cohort);
const [isLoading, setIsLoading] = React.useState(false);
const history = useHistory();
- Read upRead up
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 List
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export default function List() {
const history = useHistory();
const { user, sessionPhase1 } = useSelector((state: AuthState) => state.Auth);
const cohorts = useSelector((state: CohortState) => state.Cohorts);
- Read upRead up
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 buildRequestPath
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
export function buildRequestPath(path: BasicRoute["path"], params: BasicRoute["params"]): string {
let finalPath = path;
if (params && Object.keys(params).length > 0) {
for (const paramKey in params) {
const value = params[paramKey];
- Read upRead up
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
function validateSchool(data) {
if (data.isAbroad) {
if (!data?.school?.fullName) return false;
if (!data?.school?.country) return false;
return true;
- Read upRead up
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 157.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76