Skip to content

Commit

Permalink
chore(updating for PMD rules):
Browse files Browse the repository at this point in the history
  • Loading branch information
codefriar committed Jan 17, 2024
1 parent 9f24215 commit 1456f67
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/FeatureFlagTests.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
`ISTEST`

`APIVERSION: 58`

`STATUS: ACTIVE`
Expand Down
12 changes: 12 additions & 0 deletions docs/Log.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
`APIVERSION: 58`

`STATUS: ACTIVE`

Generic logging framework that persists across DML reversions by publishing a Platform Event
Expand Down Expand Up @@ -88,6 +90,16 @@ Add an formatted exception message to the buffer without publishing it.

Publish any messages currently in the buffer, without adding any new ones.

### `private static void handlePublishingErrors(List<Database.SaveResult> publishResults)`

this method is a stub for what your org wants to do when publishing logs fails.

#### Parameters

| Param | Description |
| ---------------- | ------------------------------------------------------------- |
| `publishResults` | List<Database.SaveResult> the list of save results to handle. |

### `private static void alsoPublishToStandardLogs(List<Log__e> logEvents)`

`SUPPRESSWARNINGS`
Expand Down
6 changes: 5 additions & 1 deletion docs/UniversalFlowInputOutput.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
`APIVERSION: 58`

`STATUS: ACTIVE`

This is a common object for passing data from a flow, into a class method, and back out to flow.
Expand Down Expand Up @@ -64,7 +66,9 @@ While the parameters list is used for passing parameters to the method you're ca

### `public Map<String,Object> toCallableParamMap()`

Method is responsible for converting the list of UniversalFlowInputOutputParameter objects delivered by the Flow action framework, to a Map&lt;String, Object&gt; needed by the Callable interface. Note, this is a hard limitation of the Flow action framework and the Apex Defined Data Types. This is not a limitation of this pattern / framework. If you want to, say pass a list of records to a method, you'll need to pass a list of strings, and query for the objects in the Apex. #sorryNothingICanDo.
`SUPPRESSWARNINGS`

Method is responsible for converting the list of UniversalFlowInputOutputParameter objects delivered by the Flow action framework, to a Map&lt;String, Object&gt; needed by the Callable interface. Note, this is a hard limitation of the Flow action framework and the Apex Defined Data Types. This is not a limitation of this pattern / framework. If you want to, say pass a list of records to a method, you'll need to pass a list of strings, and query for the objects in the Apex. #sorryNothingICanDo. Note: This method is currently suppressing PMD warnings for cognitive, standard and cyclomatic complexity as as method length. Unfortunately, I don't see a good re-factor path forward to reduce these, as the sheer number of if statements is what's killing it.

#### Returns

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @description This is a common object for passing data from a flow, into a class method, and back out to flow.
*/
@SuppressWarnings('PMD.StdCyclomaticComplexity')
public class UniversalFlowInputOutput {
/**
* @description String representing Apex recognized name of the class you're instantiating.
Expand Down Expand Up @@ -63,8 +64,16 @@ public class UniversalFlowInputOutput {
* is a hard limitation of the Flow action framework and the Apex Defined Data Types. This is not a limitation
* of this pattern / framework. If you want to, say pass a list of records to a method, you'll need to pass a
* list of strings, and query for the objects in the Apex. #sorryNothingICanDo.
*
* Note: This method is currently suppressing PMD warnings for cognitive, standard and cyclomatic complexity as
* as method length. Unfortunately, I don't see a good re-factor path forward to reduce these, as the sheer number
* of if statements is what's killing it.
*
* @return Map<String, Object> This returns a map of parameters you're passing to your method.
*/
@SuppressWarnings(
'PMD.cognitiveComplexity, PMD.CyclomaticComplexity, PMD.NcssMethodCount, PMD.StdCyclomaticComplexity'
)
public Map<String, Object> toCallableParamMap() {
Map<String, Object> paramMap = new Map<String, Object>();
if (parameters == null) {
Expand Down
10 changes: 5 additions & 5 deletions force-app/main/default/classes/ULID/ULID.cls
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public with sharing class ULID {
/**
* This character set is the complete list of allowed characters in
* @description This character set is the complete list of allowed characters in
* a ULID string. It intentionally does not include characters that
* may be ambiguously read, such as i, l, o, and u characters.
*/
Expand Down Expand Up @@ -65,7 +65,7 @@ public with sharing class ULID {
* @return `String`
*/
public static String generate() {
return encodeTimestamp(DateTime.now().getTime(), TIMELENGTH) + generateRandomString(RANDOMLENGTH);
return encodeTimestamp(Datetime.now().getTime(), TIMELENGTH) + generateRandomString(RANDOMLENGTH);
}

/**
Expand All @@ -78,7 +78,7 @@ public with sharing class ULID {
private static String encodeTimestamp(Long dtSeed, Long timeLength) {
Long modulo;
String retString = '';
for (Long l = timeLength; timeLength > 0; timeLength--) {
for (Long timestampIterationVar = timeLength; timeLength > 0; timeLength--) {
modulo = Math.mod(dtSeed, CHARACTERSETSIZE);
retString = CHARACTERSET[modulo.intValue()] + retString;
dtSeed = (dtSeed - modulo) / CHARACTERSETSIZE;
Expand All @@ -96,8 +96,8 @@ public with sharing class ULID {
*/
private static String generateRandomString(Integer length) {
Integer[] retString = new List<Integer>(length);
for (Integer l = 0; l < length; l++) {
retString[l] = fetchRandomCharacterFromCharacterSet().charAt(0);
for (Integer localIterationCounter = 0; localIterationCounter < length; localIterationCounter++) {
retString[localIterationCounter] = fetchRandomCharacterFromCharacterSet().charAt(0);
}
return String.fromCharArray(retString);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@SuppressWarnings('PMD.ApexUnitTestClassShouldHaveRunAs')
@IsTest
class FeatureFlagTests {
@IsTest
Expand Down Expand Up @@ -121,11 +122,11 @@ class FeatureFlagTests {
)
);
dataProvider.overridePerCustomPermissionOverrides(customPermOverrides);
FeatureFlag ff = new FeatureFlag(dataProvider);
FeatureFlag featureFlag = new FeatureFlag(dataProvider);

System.runAs(new User(Id = UserInfo.getUserId())) {
Test.startTest();
Boolean result = ff.isEnabled('TestFlag');
Boolean result = featureFlag.isEnabled('TestFlag');
Test.stopTest();
Assert.areEqual(true, result, 'Expected TestFlag to be enabled by custom permission');
}
Expand Down
15 changes: 12 additions & 3 deletions force-app/main/default/classes/log/Log.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @see LogException
* @see LogTriggerHandler
*/
@SuppressWarnings('PMD.CognitiveComplexity')
public with sharing class Log {
public static Boolean publishToStandardLogs = false;

Expand Down Expand Up @@ -96,17 +97,25 @@ public with sharing class Log {
}
alsoPublishToStandardLogs(rawLogs);
List<Database.SaveResult> publishResults = EventBus.publish(rawLogs);
handlePublishingErrors(publishResults);

this.buffer.clear();
}

/**
* @description this method is a stub for what your org wants to do when publishing logs fails.
* @param publishResults List<Database.SaveResult> the list of save results to handle.
*/
private static void handlePublishingErrors(List<Database.SaveResult> publishResults) {
if (publishResults.size() > 0) {
for (Database.SaveResult result : publishResults) {
if (!result.isSuccess()) {
for (Database.Error err : result.getErrors()) {
System.debug('Error returned: ' + err.getStatusCode() + ' - ' + err.getMessage());
System.debug(LoggingLevel.ERROR, 'Error returned: ' + err.getStatusCode() + ' - ' + err.getMessage());
}
}
}
}

this.buffer.clear();
}

/**
Expand Down

0 comments on commit 1456f67

Please sign in to comment.