GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] Invalid Apex in Cognitive Complexity tests · Issue #2358 · pmd/pmd

[apex] Invalid Apex in Cognitive Complexity tests  #2358

New issue
Copy link
New issue
Copy link
Closed
#2383
Closed
[apex] Invalid Apex in Cognitive Complexity tests #2358
#2383
Copy link
Assignees
gwilymatgearset
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
6.23.0

Description

@rsoesemann
rsoesemann
opened on Mar 17, 2020
Issue body actions

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:

pmd/pmd-apex/src/main/resources/category/apex/design.xml

Lines 112 to 143 in 31bf08a

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;
}
}

Activity

  1. rsoesemann
    self-assigned this
    on Mar 17, 2020
  2. rsoesemann
    changed the title [-][APEX[/-] [+][apex] Cognitive Complexity rules tests contain invalid Apex code[/+] on Mar 17, 2020
  3. rsoesemann
    removed their assignment
    on Mar 17, 2020
  4. rsoesemann
    added
    a:bugPMD crashes or fails to analyse a file.
    on Mar 17, 2020
  5. rsoesemann
    added this to the 6.23.0 milestone on Mar 17, 2020
  6. rsoesemann
    changed the title [-][apex] Cognitive Complexity rules tests contain invalid Apex code[/-] [+][apex] Cognitive Complexity tests us invalid Apex[/+] on Mar 17, 2020
  7. rsoesemann
    changed the title [-][apex] Cognitive Complexity tests us invalid Apex[/-] [+][apex] Invalid Apex in Cognitive Complexity tests [/+] on Mar 17, 2020
  8. adangel
    added
    help-wanted
    good first issueA great starting point for new contributors
    on Mar 20, 2020
  9. rsoesemann commented on Mar 20, 2020

    @rsoesemann
    rsoesemann
    on Mar 20, 2020
    MemberAuthor
    More actions

    @adangel @gwilymatgearset will work on this. The original contributor. I couldnt assign it to him. Can you?

  10. adangel commented on Mar 20, 2020

    @adangel
    adangel
    on Mar 20, 2020
    Member
    More actions

    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
  11. adangel
    removed
    good first issueA great starting point for new contributors
    help-wanted
    on Mar 20, 2020
  12. gwilymatgearset
    self-assigned this
    on Mar 27, 2020
  13. gwilymatgearset commented on Mar 27, 2020

    @gwilymatgearset
    gwilymatgearset
    on Mar 27, 2020
    Collaborator
    More actions

    @rsoesemann I'm slightly confused by 2 of your comments :)

    Uses double quotes instead of single quotes for Strings

    That makes it invalid apex doesn't it?
    image

    Uses Lowercase Type names string instead of String

    I went for upper case rather than lower case here because that's what salesforce do in all of their documentation (and what they do in trailhead)
    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_variables.htm

  14. rsoesemann commented on Mar 27, 2020

    @rsoesemann
    rsoesemann
    on Mar 27, 2020
    MemberAuthor
    More actions

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

  15. gwilymatgearset commented on Mar 27, 2020

    @gwilymatgearset
    gwilymatgearset
    on Mar 27, 2020
    Collaborator
    More actions

    Can do :).

    Reacted by Robert Sösemann
  16. rsoesemann
    closed this as completedin #2383on Mar 27, 2020
  17. adangel
    added a commit that references this issue on Mar 27, 2020

    [doc] Update release notes, refs #2383, fixes #2358

    This issue will close once commit 409b35d is merged into the 'main' branch.
    409b35d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gwilymatgearset
    gwilymatgearset

Labels

a:bugPMD crashes or fails to analyse a file.

Type

No type

Projects

No projects

    Milestone

    • 6.23.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.