From 9810bfc3cc94295d9091d9324a169f05641f1dfe Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 6 Sep 2024 18:42:03 +0200 Subject: [PATCH] [apex] Verify CognitiveComplexity for triggers --- .../rule/design/xml/CognitiveComplexity.xml | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/design/xml/CognitiveComplexity.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/design/xml/CognitiveComplexity.xml index 931578da46..034ca90956 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/design/xml/CognitiveComplexity.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/design/xml/CognitiveComplexity.xml @@ -222,4 +222,40 @@ public class Foo { } ]]> + + + Cognitive Complexity within triggers (#5138) + 15 + 1 + 2 + + The trigger 'AccountTrigger' has a cognitive complexity of 18, current threshold is 15 + + updatedAccounts = Trigger.new; + if(trigger.isAfter){ + Map mapOfOldValues = trigger.oldMap; + Map accountWithOnboardingTemplateIDs = new Map(); + for(Account updated_Account : updatedAccounts) { + if(updated_Account.Onboarding_Plan__c != null) + { + if(mapOfOldValues == null){ + accountWithOnboardingTemplateIDs.put(updated_Account.Id, updated_Account.Onboarding_Plan__c); + } else { + if(updated_Account.Onboarding_Plan__c != mapOfOldValues.get(updated_Account.Id).Onboarding_Plan__c) + accountWithOnboardingTemplateIDs.put(updated_Account.Id, updated_Account.Onboarding_Plan__c); + } + } + } //End For + + if(accountWithOnboardingTemplateIDs.size() > 0){ + OnboardingPlanService.updateContactsWithOndbPlan(accountWithOnboardingTemplateIDs); + } + } +} +]]> +