Batchable & Schedulable class has cyclomatic complexity of 48
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
Background
I have a class which implements Database.Batchable<Sobject>
and Schedulable
and when I run PMD I get this problem:
The class 'MyClassBatchJob' has a total cyclomatic complexity of 48 (highest 5).
Questions
- How is the Apex cyclomatic complexity calculated?
- How should I approach Batchable & Schedulable classes to reduce cyclomatic complexity?
apex batch scheduled-apex pmd cyclomatic-complexity
add a comment |Â
up vote
1
down vote
favorite
Background
I have a class which implements Database.Batchable<Sobject>
and Schedulable
and when I run PMD I get this problem:
The class 'MyClassBatchJob' has a total cyclomatic complexity of 48 (highest 5).
Questions
- How is the Apex cyclomatic complexity calculated?
- How should I approach Batchable & Schedulable classes to reduce cyclomatic complexity?
apex batch scheduled-apex pmd cyclomatic-complexity
Bear in mind that such metrics are great for drawing attention to parts of your code base that might benefit from some refactoring. The real metric though is more subjective and is whether others can easily and safely understand and modify the code in the future. That has multiple aspects including using good naming.
â Keith C
2 hours ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Background
I have a class which implements Database.Batchable<Sobject>
and Schedulable
and when I run PMD I get this problem:
The class 'MyClassBatchJob' has a total cyclomatic complexity of 48 (highest 5).
Questions
- How is the Apex cyclomatic complexity calculated?
- How should I approach Batchable & Schedulable classes to reduce cyclomatic complexity?
apex batch scheduled-apex pmd cyclomatic-complexity
Background
I have a class which implements Database.Batchable<Sobject>
and Schedulable
and when I run PMD I get this problem:
The class 'MyClassBatchJob' has a total cyclomatic complexity of 48 (highest 5).
Questions
- How is the Apex cyclomatic complexity calculated?
- How should I approach Batchable & Schedulable classes to reduce cyclomatic complexity?
apex batch scheduled-apex pmd cyclomatic-complexity
apex batch scheduled-apex pmd cyclomatic-complexity
asked 2 hours ago
Robs
1,208323
1,208323
Bear in mind that such metrics are great for drawing attention to parts of your code base that might benefit from some refactoring. The real metric though is more subjective and is whether others can easily and safely understand and modify the code in the future. That has multiple aspects including using good naming.
â Keith C
2 hours ago
add a comment |Â
Bear in mind that such metrics are great for drawing attention to parts of your code base that might benefit from some refactoring. The real metric though is more subjective and is whether others can easily and safely understand and modify the code in the future. That has multiple aspects including using good naming.
â Keith C
2 hours ago
Bear in mind that such metrics are great for drawing attention to parts of your code base that might benefit from some refactoring. The real metric though is more subjective and is whether others can easily and safely understand and modify the code in the future. That has multiple aspects including using good naming.
â Keith C
2 hours ago
Bear in mind that such metrics are great for drawing attention to parts of your code base that might benefit from some refactoring. The real metric though is more subjective and is whether others can easily and safely understand and modify the code in the future. That has multiple aspects including using good naming.
â Keith C
2 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
Roughly speaking, too many branching constructs (if
, for
, etc.) in a single method. It's usually a sign that your methods could be broken down into more readable chunks.
Their complete definition:
The complexity of methods directly affects maintenance costs and
readability. Concentrating too much decisional logic in a single
method makes its behaviour hard to read and change.
Cyclomatic complexity assesses the complexity of a method by counting
the number of decision points in a method, plus one for the method
entry. Decision points are places where the control flow jumps to
another place in the program. As such, they include all control flow
statements, such as âÂÂifâÂÂ, âÂÂwhileâÂÂ, âÂÂforâÂÂ, and âÂÂcaseâÂÂ.
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote
moderate complexity, 8-10 denote high complexity, and 11+ is very high
complexity. By default, this rule reports methods with a complexity >=
10. Additionnally, classes with many methods of moderate complexity get reported as well once the total of their methodsâ complexities
reaches 40, even if none of the methods was directly reported.
Reported methods should be broken down into several smaller methods.
Reported classes should probably be broken down into subcomponents.
https://pmd.github.io/pmd-6.7.0/pmd_rules_apex_design.html#cyclomaticcomplexity
Edit
Re-reading your message, it looks like it's probably that the class has too many methods and the total is too high, rather than any particular method being very bad. So, you should probably break the class into a few classes, each of which only does one thing. If you post your code (maybe as a separate question on how to decompose the class), you may be able to get specific help on doing that.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Roughly speaking, too many branching constructs (if
, for
, etc.) in a single method. It's usually a sign that your methods could be broken down into more readable chunks.
Their complete definition:
The complexity of methods directly affects maintenance costs and
readability. Concentrating too much decisional logic in a single
method makes its behaviour hard to read and change.
Cyclomatic complexity assesses the complexity of a method by counting
the number of decision points in a method, plus one for the method
entry. Decision points are places where the control flow jumps to
another place in the program. As such, they include all control flow
statements, such as âÂÂifâÂÂ, âÂÂwhileâÂÂ, âÂÂforâÂÂ, and âÂÂcaseâÂÂ.
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote
moderate complexity, 8-10 denote high complexity, and 11+ is very high
complexity. By default, this rule reports methods with a complexity >=
10. Additionnally, classes with many methods of moderate complexity get reported as well once the total of their methodsâ complexities
reaches 40, even if none of the methods was directly reported.
Reported methods should be broken down into several smaller methods.
Reported classes should probably be broken down into subcomponents.
https://pmd.github.io/pmd-6.7.0/pmd_rules_apex_design.html#cyclomaticcomplexity
Edit
Re-reading your message, it looks like it's probably that the class has too many methods and the total is too high, rather than any particular method being very bad. So, you should probably break the class into a few classes, each of which only does one thing. If you post your code (maybe as a separate question on how to decompose the class), you may be able to get specific help on doing that.
add a comment |Â
up vote
3
down vote
Roughly speaking, too many branching constructs (if
, for
, etc.) in a single method. It's usually a sign that your methods could be broken down into more readable chunks.
Their complete definition:
The complexity of methods directly affects maintenance costs and
readability. Concentrating too much decisional logic in a single
method makes its behaviour hard to read and change.
Cyclomatic complexity assesses the complexity of a method by counting
the number of decision points in a method, plus one for the method
entry. Decision points are places where the control flow jumps to
another place in the program. As such, they include all control flow
statements, such as âÂÂifâÂÂ, âÂÂwhileâÂÂ, âÂÂforâÂÂ, and âÂÂcaseâÂÂ.
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote
moderate complexity, 8-10 denote high complexity, and 11+ is very high
complexity. By default, this rule reports methods with a complexity >=
10. Additionnally, classes with many methods of moderate complexity get reported as well once the total of their methodsâ complexities
reaches 40, even if none of the methods was directly reported.
Reported methods should be broken down into several smaller methods.
Reported classes should probably be broken down into subcomponents.
https://pmd.github.io/pmd-6.7.0/pmd_rules_apex_design.html#cyclomaticcomplexity
Edit
Re-reading your message, it looks like it's probably that the class has too many methods and the total is too high, rather than any particular method being very bad. So, you should probably break the class into a few classes, each of which only does one thing. If you post your code (maybe as a separate question on how to decompose the class), you may be able to get specific help on doing that.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Roughly speaking, too many branching constructs (if
, for
, etc.) in a single method. It's usually a sign that your methods could be broken down into more readable chunks.
Their complete definition:
The complexity of methods directly affects maintenance costs and
readability. Concentrating too much decisional logic in a single
method makes its behaviour hard to read and change.
Cyclomatic complexity assesses the complexity of a method by counting
the number of decision points in a method, plus one for the method
entry. Decision points are places where the control flow jumps to
another place in the program. As such, they include all control flow
statements, such as âÂÂifâÂÂ, âÂÂwhileâÂÂ, âÂÂforâÂÂ, and âÂÂcaseâÂÂ.
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote
moderate complexity, 8-10 denote high complexity, and 11+ is very high
complexity. By default, this rule reports methods with a complexity >=
10. Additionnally, classes with many methods of moderate complexity get reported as well once the total of their methodsâ complexities
reaches 40, even if none of the methods was directly reported.
Reported methods should be broken down into several smaller methods.
Reported classes should probably be broken down into subcomponents.
https://pmd.github.io/pmd-6.7.0/pmd_rules_apex_design.html#cyclomaticcomplexity
Edit
Re-reading your message, it looks like it's probably that the class has too many methods and the total is too high, rather than any particular method being very bad. So, you should probably break the class into a few classes, each of which only does one thing. If you post your code (maybe as a separate question on how to decompose the class), you may be able to get specific help on doing that.
Roughly speaking, too many branching constructs (if
, for
, etc.) in a single method. It's usually a sign that your methods could be broken down into more readable chunks.
Their complete definition:
The complexity of methods directly affects maintenance costs and
readability. Concentrating too much decisional logic in a single
method makes its behaviour hard to read and change.
Cyclomatic complexity assesses the complexity of a method by counting
the number of decision points in a method, plus one for the method
entry. Decision points are places where the control flow jumps to
another place in the program. As such, they include all control flow
statements, such as âÂÂifâÂÂ, âÂÂwhileâÂÂ, âÂÂforâÂÂ, and âÂÂcaseâÂÂ.
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote
moderate complexity, 8-10 denote high complexity, and 11+ is very high
complexity. By default, this rule reports methods with a complexity >=
10. Additionnally, classes with many methods of moderate complexity get reported as well once the total of their methodsâ complexities
reaches 40, even if none of the methods was directly reported.
Reported methods should be broken down into several smaller methods.
Reported classes should probably be broken down into subcomponents.
https://pmd.github.io/pmd-6.7.0/pmd_rules_apex_design.html#cyclomaticcomplexity
Edit
Re-reading your message, it looks like it's probably that the class has too many methods and the total is too high, rather than any particular method being very bad. So, you should probably break the class into a few classes, each of which only does one thing. If you post your code (maybe as a separate question on how to decompose the class), you may be able to get specific help on doing that.
answered 1 hour ago
Aidan
5,825937
5,825937
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f233367%2fbatchable-schedulable-class-has-cyclomatic-complexity-of-48%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Bear in mind that such metrics are great for drawing attention to parts of your code base that might benefit from some refactoring. The real metric though is more subjective and is whether others can easily and safely understand and modify the code in the future. That has multiple aspects including using good naming.
â Keith C
2 hours ago