Skip to content

Conversation

@codefriar
Copy link
Owner

@codefriar codefriar commented Oct 18, 2023

Summary by CodeRabbit

  • New Feature: Introduced a new Tuple class to provide key-value pair functionality similar to Map, enhancing support for various primitive data types.
  • Refactor: Updated method signatures across multiple classes for explicit type declarations, improving code clarity and maintainability.
  • Chore: Modified GitHub Actions workflow file inputs and conditions for better CI/CD process control.
  • Style: Improved documentation by updating return types and descriptions of several methods.
  • Chore: Updated .gitignore and security rules in pmd/ruleset.xml for better repository management.

Signed-off-by: kpoorman <kjp@codefriar.com>
A generic Apex Defined Type for use in flows. Contains primitive @AuraEnabled, @invocableVariable variables of every available type, as well as sObject and list<sObject> and logic to auto cast the incoming Object value to the correct primitive type.

Signed-off-by: kpoorman <kjp@codefriar.com>
@github-actions
Copy link

github-actions bot commented Oct 18, 2023

Image description CodeRabbit

Walkthrough

This pull request introduces a new Tuple class to provide key-value pair functionality in Apex, updates GitHub Actions workflow file, enhances code clarity by updating method return types across multiple classes, removes a file from the repository, and adds security rule exclusions in an XML file.

Changes

Files Summary
Tuple.cls, Tuple.cls-meta.xml, docs/Tuple.md, docs/home.md Introduced a new Tuple class that acts as a polyfill for the Map<String, Object> data type in Apex. It provides constructors, fields, and methods to work with various primitive data types.
.github/workflows/ci-pr.yml Updated the GitHub Actions workflow file by modifying inputs for the openai-review-action step and commenting out the Create prerelease scratch org step.
Various docs/*.md files Updated return types and descriptions of several methods across multiple classes for improved code clarity and maintainability.
.gitignore Removed the "pmd/pmd.csv" file from the repository.
pmd/ruleset.xml Added three exclude patterns related to security rules for Apex, preventing specific directories from being analyzed by the security rules.

🐇💻

Code changes here, code changes there,

A Tuple class appears, with much flair.

Workflow tweaks, and types made clear,

Security rules, have no fear.

Celebrate the changes, far and near,

For better code, we all cheer! 🎉🥳


Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 8c3b9aa and c00518b commits.
Files selected (4)
  • docs/Tuple.md (1)
  • docs/home.md (1)
  • force-app/main/default/classes/Data Structures/Tuple.cls (1)
  • force-app/main/default/classes/Data Structures/Tuple.cls-meta.xml (1)
Files skipped from review due to trivial changes (2)
  • docs/home.md
  • force-app/main/default/classes/Data Structures/Tuple.cls-meta.xml
Review comments generated (18)
  • Review: 18
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Signed-off-by: kpoorman <kjp@codefriar.com>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between c00518b and 96372af commits.
Files selected (2)
  • docs/Tuple.md (1)
  • force-app/main/default/classes/Data Structures/Tuple.cls (1)
Files skipped from review due to trivial changes (1)
  • docs/Tuple.md
Review comments generated (1)
  • Review: 1
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Signed-off-by: kpoorman <kjp@codefriar.com>
Signed-off-by: kpoorman <kjp@codefriar.com>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 96372af and 83a3a29 commits.
Files selected (2)
  • docs/Tuple.md (1)
  • force-app/main/default/classes/Data Structures/Tuple.cls (1)
Review comments generated (12)
  • Review: 12
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Removed the pre-release option

Signed-off-by: kpoorman <kjp@codefriar.com>
@codefriar codefriar requested a review from dschach October 18, 2023 04:12
Copy link
Collaborator

@dschach dschach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fascinated by this class. Seems you've accounted for every data type.
I added a comment for List.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 83a3a29 and 19f70e5 commits.
Files selected (1)
  • .github/workflows/ci-pr.yml (2)
Files skipped from review due to trivial changes (1)
  • .github/workflows/ci-pr.yml
Review comments generated (0)
  • Review: 0
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

@codefriar codefriar changed the title Feat/add tupple Feat/add tuple Oct 19, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 8c3b9aa and 19f70e5 commits.
Files selected (5)
  • .github/workflows/ci-pr.yml (2)
  • docs/Tuple.md (1)
  • docs/home.md (1)
  • force-app/main/default/classes/Data Structures/Tuple.cls (1)
  • force-app/main/default/classes/Data Structures/Tuple.cls-meta.xml (1)
Files skipped from review due to trivial changes (4)
  • docs/Tuple.md
  • docs/home.md
  • force-app/main/default/classes/Data Structures/Tuple.cls
  • force-app/main/default/classes/Data Structures/Tuple.cls-meta.xml
Review comments generated (2)
  • Review: 2
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 19f70e5 and b140af0 commits.
Files selected (50)
  • .github/workflows/ci-pr.yml (1)
  • docs/BulkCallable.md (2)
  • docs/CanTheUser.md (24)
  • docs/CanTheUserTests.md (1)
  • docs/CustomInvocable.md (5)
  • docs/ExampleQueueableProcessSteps.md (1)
  • docs/FF.md (3)
  • docs/FailsafeExceptionHandler.md (1)
  • docs/FeatureFlag.md (6)
  • docs/FeatureFlagCommonTests.md (4)
  • docs/FeatureFlagDataProvider.md (5)
  • docs/HttpCalloutMockFactory.md (2)
  • docs/IdFactory.md (6)
  • docs/Log.md (1)
  • docs/LogMessage.md (1)
  • docs/LogTriggerHandler.md (3)
  • docs/MetadataTriggerFramework.md (3)
  • docs/MetadataTriggerQueryService.md (3)
  • docs/MethodSignature.md (8)
  • docs/MockedMethod.md (16)
  • docs/OrgShape.md (5)
  • docs/Ouroboros.md (2)
  • docs/OuroborosFinalizer.md (1)
  • docs/OuroborosTests.md (1)
  • docs/Polyfills.md (10)
  • docs/Query.md (1)
  • docs/QueueableProcess.md (3)
  • docs/QueueableProcessDataProvider.md (1)
  • docs/QueueableProcessTests.md (1)
  • docs/QuiddityGuard.md (2)
  • docs/RestClient.md (1)
  • docs/RestClientLib.md (13)
  • docs/RestLib.md (1)
  • docs/RestLibApiCall.md (1)
  • docs/SOQL.md (1)
  • docs/SOQLAgregate.md (1)
  • docs/SOSL.md (1)
  • docs/Safely.md (12)
  • docs/SampleHandler.md (3)
  • docs/Stub.md (9)
  • docs/StubUtilities.md (2)
  • docs/TestFactory.md (16)
  • docs/TriggerContext.md (1)
  • docs/TriggerFramework.md (3)
  • docs/TriggerFrameworkLoopCount.md (1)
  • docs/UFInvocable.md (7)
  • docs/ULID.md (3)
  • docs/UniversalBulkInvocable.md (2)
  • docs/UniversalFlowInputOutput.md (1)
  • docs/UniversalInvocable.md (2)
Files not summarized due to errors (1)
  • docs/CanTheUser.md (diff tokens exceeds limit)
Files not reviewed due to errors (16)
  • docs/FeatureFlagCommonTests.md (no response)
  • docs/CanTheUser.md (no response)
  • docs/FeatureFlagDataProvider.md (no response)
  • docs/LogTriggerHandler.md (no response)
  • docs/MetadataTriggerFramework.md (no response)
  • docs/MethodSignature.md (no response)
  • docs/OrgShape.md (no response)
  • docs/MockedMethod.md (no response)
  • docs/Ouroboros.md (no response)
  • docs/QuiddityGuard.md (no response)
  • docs/SOQL.md (no response)
  • docs/Safely.md (no response)
  • docs/Stub.md (no response)
  • docs/TestFactory.md (no response)
  • docs/UniversalBulkInvocable.md (no response)
  • docs/UniversalFlowInputOutput.md (no response)
Files skipped from review due to trivial changes (28)
  • .github/workflows/ci-pr.yml
  • docs/CanTheUserTests.md
  • docs/ExampleQueueableProcessSteps.md
  • docs/FF.md
  • docs/FailsafeExceptionHandler.md
  • docs/FeatureFlag.md
  • docs/IdFactory.md
  • docs/Log.md
  • docs/LogMessage.md
  • docs/MetadataTriggerQueryService.md
  • docs/OuroborosFinalizer.md
  • docs/OuroborosTests.md
  • docs/Polyfills.md
  • docs/Query.md
  • docs/QueueableProcess.md
  • docs/QueueableProcessTests.md
  • docs/RestClient.md
  • docs/RestClientLib.md
  • docs/RestLib.md
  • docs/RestLibApiCall.md
  • docs/SOQLAgregate.md
  • docs/SampleHandler.md
  • docs/StubUtilities.md
  • docs/TriggerContext.md
  • docs/TriggerFramework.md
  • docs/TriggerFrameworkLoopCount.md
  • docs/UFInvocable.md
  • docs/ULID.md
Review comments generated (16)
  • Review: 6
  • LGTM: 10

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

codefriar and others added 12 commits October 19, 2023 17:31
Bumps [@cparra/apexdocs](https://github.com/cesarParra/apexdocs) from 2.17.0 to 2.17.1.
- [Release notes](https://github.com/cesarParra/apexdocs/releases)
- [Commits](cesarParra/apexdocs@v2.17.0...v2.17.1)

---
updated-dependencies:
- dependency-name: "@cparra/apexdocs"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [eslint](https://github.com/eslint/eslint) from 8.50.0 to 8.51.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.50.0...v8.51.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [@cparra/apexdocs](https://github.com/cesarParra/apexdocs) from 2.17.1 to 2.17.2.
- [Release notes](https://github.com/cesarParra/apexdocs/releases)
- [Commits](cesarParra/apexdocs@v2.17.1...v2.17.2)

---
updated-dependencies:
- dependency-name: "@cparra/apexdocs"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [marked](https://github.com/markedjs/marked) from 9.1.0 to 9.1.1.
- [Release notes](https://github.com/markedjs/marked/releases)
- [Changelog](https://github.com/markedjs/marked/blob/master/.releaserc.json)
- [Commits](markedjs/marked@v9.1.0...v9.1.1)

---
updated-dependencies:
- dependency-name: marked
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [marked](https://github.com/markedjs/marked) from 9.1.1 to 9.1.2.
- [Release notes](https://github.com/markedjs/marked/releases)
- [Changelog](https://github.com/markedjs/marked/blob/master/.releaserc.json)
- [Commits](markedjs/marked@v9.1.1...v9.1.2)

---
updated-dependencies:
- dependency-name: marked
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [lint-staged](https://github.com/okonet/lint-staged) from 14.0.1 to 15.0.1.
- [Release notes](https://github.com/okonet/lint-staged/releases)
- [Changelog](https://github.com/lint-staged/lint-staged/blob/master/CHANGELOG.md)
- [Commits](lint-staged/lint-staged@v14.0.1...v15.0.1)

---
updated-dependencies:
- dependency-name: lint-staged
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.23.0 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: kpoorman <kjp@codefriar.com>
Signed-off-by: kpoorman <kjp@codefriar.com>
Signed-off-by: kpoorman <kjp@codefriar.com>
…tch org

Signed-off-by: kpoorman <kjp@codefriar.com>
@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (671272e) 95.00% compared to head (56bec3a) 95.00%.
Report is 42 commits behind head on main.

❗ Current head 56bec3a differs from pull request most recent head b8a13cd. Consider uploading reports for the commit b8a13cd to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #122   +/-   ##
=======================================
  Coverage   95.00%   95.00%           
=======================================
  Files          32       32           
  Lines        2002     2002           
=======================================
  Hits         1902     1902           
  Misses        100      100           
Flag Coverage Δ
Apex 95.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 83a3a29 and b8a13cd commits.
Files selected (5)
  • .github/workflows/ci-pr.yml (1)
  • .gitignore (1)
  • force-app/main/default/classes/dataStructures/Tuple.cls (1)
  • force-app/main/default/classes/dataStructures/Tuple.cls-meta.xml (1)
  • pmd/ruleset.xml (1)
Files ignored due to filter (1)
  • config/project-scratch-def.json
Files skipped from review due to trivial changes (4)
  • .github/workflows/ci-pr.yml
  • .gitignore
  • force-app/main/default/classes/dataStructures/Tuple.cls-meta.xml
  • pmd/ruleset.xml
Review comments generated (1)
  • Review: 1
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +1 to +152
/**
* @description Tuple represents a key-value pair. Kinda. Don't come at me math nerds.
*
* You may be asking why this exists, given the existence of Map. Unfortuately Map isn't available everywhere.
* Notably, it's not available in Apex-defined Data Types used by Flow/Invocable actions.
*
* Additionally, `Object` is not a valid data type in Apex-defined Data Types, so we can't use a list of objects
* that have a string key, and Object value. This is the next best thing. A kind of polyfill for Map<String,Object>
* for use in Apex-defined Data Types.
*
* See also: https://help.salesforce.com/s/articleView?id=sf.flow_considerations_apex_data_type.htm&type=5
* Available primitive datatypes available for use in tuple:
* Boolean, Integer, Long, Decimal, Double, Date, DateTime, and String. Single values and lists are supported for each data type.
*/
@SuppressWarnings('PMD.StdCyclomaticComplexity')
public with sharing class Tuple {
@AuraEnabled
@InvocableVariable
public String key;

@AuraEnabled
@InvocableVariable
public Boolean[] booleans;
@AuraEnabled
@InvocableVariable
public Boolean booleanValue;
@AuraEnabled
@InvocableVariable
public Date dateValue;
@AuraEnabled
@InvocableVariable
public Date[] dates;
@AuraEnabled
@InvocableVariable
public Datetime[] datetimes;
@AuraEnabled
@InvocableVariable
public Datetime dateTimeValue;
@AuraEnabled
@InvocableVariable
public Double doubleValue;
@AuraEnabled
@InvocableVariable
public Double[] doubles;
@AuraEnabled
@InvocableVariable
public Decimal decimalValue;
@AuraEnabled
@InvocableVariable
public Decimal[] decimals;
@AuraEnabled
@InvocableVariable
public Integer integerValue;
@AuraEnabled
@InvocableVariable
public Integer[] integers;
@AuraEnabled
@InvocableVariable
public Long longValue;
@AuraEnabled
@InvocableVariable
public Long[] longs;
@AuraEnabled
@InvocableVariable
public String stringValue;
@AuraEnabled
@InvocableVariable
public String[] strings;
@AuraEnabled
@InvocableVariable
public SObject sobjectValue;
@AuraEnabled
@InvocableVariable
public SObject[] sobjects;

/**
* @description In order to create a Tuple instance from within a flow, you need a no-arg constructor.
*/
@SuppressWarnings('PMD.EmptyStatementBlock')
public Tuple() {
}

/**
* @description standard constructor accepting a key and value
* @param key String the name of the Tuple's Key.
* @param value Object the Tuple's Value.
*/
public Tuple(String key, Object value) {
if (key == null) {
throw new TupleException('Key cannot be null');
}
if (value == null) {
throw new TupleException('Value cannot be null');
}
this.key = key;
determineTypeAndSetCastedValue(value);
}

/**
* @description Method is responsible for determining the type of the value and setting the appropriate field.
* @param value Object the Tuple's Value.
*/
@SuppressWarnings('PMD.CyclomaticComplexity, PMD.StdCyclomaticComplexity')
private void determineTypeAndSetCastedValue(Object value) {
if (value instanceof Boolean) {
this.booleanValue = (Boolean) value;
} else if (value instanceof List<Boolean>) {
this.booleans = (List<Boolean>) value;
} else if (value instanceof Datetime) {
this.dateTimeValue = (Datetime) value;
} else if (value instanceof List<Datetime>) {
this.datetimes = (List<Datetime>) value;
} else if (value instanceof Date) {
this.dateValue = (Date) value;
} else if (value instanceof List<Date>) {
this.dates = (List<Date>) value;
} else if (value instanceof Long) {
this.longValue = (Long) value;
} else if (value instanceof List<Long>) {
this.longs = (List<Long>) value;
} else if (value instanceof Integer) {
this.integerValue = (Integer) value;
} else if (value instanceof List<Integer>) {
this.integers = (List<Integer>) value;
} else if (value instanceof Decimal) {
this.decimalValue = (Decimal) value;
} else if (value instanceof List<Decimal>) {
this.decimals = (List<Decimal>) value;
} else if (value instanceof Double) {
this.doubleValue = (Double) value;
} else if (value instanceof List<Double>) {
this.doubles = (List<Double>) value;
} else if (value instanceof String) {
this.stringValue = (String) value;
} else if (value instanceof List<String>) {
this.strings = (List<String>) value;
} else if (value instanceof List<SObject>) {
this.sobjects = (List<SObject>) value;
} else if (value instanceof SObject) {
this.sobjectValue = (SObject) value;
} else {
throw new TupleException('Unsupported data type: ' + value);
}
}

/**
* @description A custom Exception type thrown when the incoming Object is not a recognized Apex-defined-type safe
* type.
*/
public class TupleException extends Exception {
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The Tuple class seems to be well implemented. It provides a way to store different types of data in a single object, which can be useful in certain scenarios where the type of data is not known beforehand or can vary. The use of AuraEnabled and InvocableVariable annotations makes this class usable in Salesforce's Lightning Web Components and Flows respectively.

However, there are some potential improvements that could be made:

  1. Error Handling: In the constructor public Tuple(String key, Object value), you're throwing exceptions if either the key or value is null. While it's good to validate inputs, consider if this is the best approach for your use case. If null values are expected or acceptable in some scenarios, this could lead to unnecessary exceptions being thrown.

  2. Maintainability: The determineTypeAndSetCastedValue(Object value) method has a high cyclomatic complexity due to the many conditional branches. This could make the code harder to maintain and test. Consider refactoring this into smaller methods or using a design pattern such as the Strategy pattern to handle different types.

  3. Performance: Each time a new Tuple object is created, the determineTypeAndSetCastedValue(Object value) method runs through a series of if statements until it finds the correct type. This could potentially impact performance if a large number of Tuple objects are being created. Consider optimizing this logic.

  4. Security: The Tuple class includes fields for storing SObject and List<SObject> types. Be aware that exposing SObjects directly can potentially expose sensitive data or allow for DML operations that bypass the usual security checks. Ensure that any usage of these fields respects the user's permissions and sharing rules.

  5. Consistency: The class uses both singular and plural field names (e.g., booleanValue and booleans). This could potentially cause confusion. Consider adopting a consistent naming convention.

Here's an example of how you might refactor the determineTypeAndSetCastedValue(Object value) method to reduce its complexity:

private void determineTypeAndSetCastedValue(Object value) {
    if (value instanceof Boolean) {
        setBooleanValue(value);
    } else if (value instanceof List<Boolean>) {
        setBooleansValue(value);
    } else if (value instanceof Datetime) {
        setDatetimeValue(value);
    } // ... continue for each type
}

private void setBooleanValue(Object value) {
    this.booleanValue = (Boolean) value;
}

private void setBooleansValue(Object value) {
    this.booleans = (List<Boolean>) value;
}

private void setDatetimeValue(Object value) {
    this.dateTimeValue = (Datetime) value;
}

// ... continue for each type

This approach breaks down the large method into smaller, more manageable methods, each responsible for setting a specific type of value. It also makes it easier to add or remove support for types in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants