GeezerVison is showing github.com — [apex] Invalid Apex in Cognitive Complexity tests · Issue #2358 · pmd/pmd
[apex] Invalid Apex in Cognitive Complexity tests #2358Labels a:bugPMD crashes or fails to analyse a file. DescriptionThe 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; |
|
} |
|
} |
Activitychanged the title [-][APEX[/-] [+][apex] Cognitive Complexity rules tests contain invalid Apex code[/+] on Mar 17, 2020changed the title [-][apex] Cognitive Complexity rules tests contain invalid Apex code[/-] [+][apex] Cognitive Complexity tests us invalid Apex[/+] on Mar 17, 2020changed the title [-][apex] Cognitive Complexity tests us invalid Apex[/-] [+][apex] Invalid Apex in Cognitive Complexity tests [/+] on Mar 17, 2020rsoesemann commented on Mar 20, 2020 adangel commented on Mar 20, 2020 I've invited him now as a outside collaborator. @gwilymatgearset can you accept the invite? Then I can assign the issue to you... thanks Reacted by Robert Sösemann gwilymatgearset commented on Mar 27, 2020 rsoesemann commented on Mar 27, 2020 @gwilymatgearset Sorry for the confusion. Your examples just dont compile because of the missing returns but other Apex examples in the same XML are faulty. I mixed this up. If you have time to fix them in one go this would be awesome. gwilymatgearset commented on Mar 27, 2020 Reacted by Robert Sösemann added a commit that references this issue on Mar 27, 2020This issue will close once commit 409b35d is merged into the 'main' branch.409b35d
MetadataMetadataa:bugPMD crashes or fails to analyse a file. DevelopmentNo branches or pull requestsIssue actions
|