Showing content from https://github.com/pmd/pmd/issues/2358 below:
[apex] Invalid Apex in Cognitive Complexity tests · Issue #2358 · pmd/pmd · GitHub
The Cognitive Complexity rule added by @gwilymatgearset in PMD 6.22 (#2297) has text sample code that is no valid Apex.
Please check and fix ALL instances but here are a few issues:
- Uses double quotes instead of single quotes for Strings
- Uses Lowercase Type names string instead of String
- method setPhoneNumberIfNotExisting is missing a return;
Here's the example code, that needs to be fixed:
public class Foo { // Has a cognitive complexity of 0 public void createAccount() { Account account = new Account(Name = 'PMD'); insert account; } // Has a cognitive complexity of 1 public Boolean setPhoneNumberIfNotExisting(Account a, String phone) { if (a.Phone == null) { // +1 a.Phone = phone; update a; } } // Has a cognitive complexity of 5 public void updateContacts(List<Contact> contacts) { List<Contact> contactsToUpdate = new List<Contact>(); for (Contact contact : contacts) { // +1 if (contact.Department == 'Finance') { // +2 contact.Title = 'Finance Specialist'; contactsToUpdate.add(contact); } else if (contact.Department == 'Sales') { // +2 contact.Title = 'Sales Specialist'; contactsToUpdate.add(contact); } } update contactsToUpdate; } }
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4