How would you improve this method? Cyclomatic complexity too high

Hello, I'm currently working on an RoR method, but it throws some rubocop warnings I've been trying to refactor for while. Do you have a better idea of how I could improve this method? Thanks

Assignment Branch Condition size for bucket_items_applies? is too high. [<9, 33, 8> 35.13/32] (convention:Metrics/AbcSize)

Cyclomatic complexity for bucket_items_applies? is too high. [8/6] (convention:Metrics/CyclomaticComplexity)

Perceived complexity for bucket_items_applies? is too high. [8/6] (convention:Metrics/PerceivedComplexity)

  def bucket_items_applies?(discount)
    @application_count = 0

    discount.bucket.bucket_items.all.each do |bucket_item|
      @cloned_items = items.map(&amp;:clone)

      bucket_item_type_id = bucket_item.product.present? ? bucket_item.product.id : bucket_item.line.id
      line_token = bucket_item.product.present? ? bucket_item.product.line.to_gid.to_s : bucket_item.line.to_gid.to_s

      matching_line_item_product_index = line_item_product_index.select { |_, product| (bucket_item.product.present? ? product.id : product.line.id) == bucket_item_type_id }

      return false if matching_line_item_product_index.blank?

      allocate_discount(matching_line_item_product_index: matching_line_item_product_index, discount: discount, bucket_item: bucket_item)

      @line_quantities_index[line_token] -= bucket_item.minimum_quantity
      @applicable_lines &lt;&lt; line_token
    end

    true
  end
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/emiliocm9
πŸ“…︎ Dec 10 2021
🚨︎ report
Cyclomatic Complexity analysis on Code Reviews

I'm looking for a Code Review tool that checks and shows the Cyclomatic Complexity of the code during a pull request, merge request, or in a dashboard from the repository.

I'm curious because besides the SonarLint extension for VS Code I haven't seen any tool that provides this type of feature, and I think that this kind of metric it's fundamental for every team.

I have tested Sonarqube and SonarCloud, but I haven't seen Cyclomatic Complexity evaluated.

Do you know guys any type of tool that evaluates the Cyclomatic Complexity of your general code for a repository that is integrated with Gitlab, GitHub, and other Git Repositories?

πŸ‘︎ 19
πŸ’¬︎
πŸ‘€︎ u/confuseparrot
πŸ“…︎ Oct 22 2021
🚨︎ report
Does anyone know of any tool for calculating the cyclomatic complexity of pascal-based source code?

Like the title indicates, I need to calculate the cyclomatic complexity of a very complex pascal-based programm. Trying to calculate it manually is pointless, so I was hoping that some tool exists.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/TriloBlitz
πŸ“…︎ Oct 21 2021
🚨︎ report
Cyclomatic Complexity.
πŸ‘︎ 216
πŸ’¬︎
πŸ‘€︎ u/Yusaku-Midory
πŸ“…︎ Mar 02 2021
🚨︎ report
WILT - Whitespace Integrated over Lines of Text (fast alternative to cyclomatic complexity checkers) github.com/ahungry/wilt
πŸ‘︎ 14
πŸ’¬︎
πŸ‘€︎ u/xenow
πŸ“…︎ Aug 22 2019
🚨︎ report
php-doc-check is an MIT licensed command line tool that use Cyclomatic Complexity to identify which functions and method could use some documentation. github.com/NielsdeBlaauw/…
πŸ‘︎ 48
πŸ’¬︎
πŸ“…︎ Jan 18 2019
🚨︎ report
Structuring CRUD handlers in web apps to reduce cyclomatic complexity

How do people structure code for web handlers for basic Create, Read, Update, Delete operations on database records?

If you start off with separate handlers for each, you get lots of code duplication. So I broke out chunks of common functionality:

  • Decode request (including authenticated ID)
  • Check authorization
  • Get current record
  • If saving:
    • Decode form submission (including checking CSRF token)
    • Validate submitted data
    • Save new record
  • Write audit log
  • Output page in read or edit mode

Each operation is basically a chain of these operations in a particular order.

The problem is, there are lots of data values which need to thread through the flow to all the chunks of code. Things like whether the request is to view or edit are indicated at the very first step, decoding the request, but they have an effect on the last step, outputting the resulting page. (e.g. an edit request may result in a read-only page plus an error.)

If I put all the values explicitly as arguments to each function, some of them have half a dozen or more arguments. So for now, I've ended up with a RequestData struct that collects all the info, and that gets passed down the chain. This bothers me aesthetically, but I can't think of a better option.

So, what are you doing to keep cyclomatic complexity low in CRUD handlers? Is there some technique I'm missing? Anyone have nice clean examples?

πŸ‘︎ 7
πŸ’¬︎
πŸ‘€︎ u/metamatic
πŸ“…︎ Feb 18 2020
🚨︎ report
Slim 4 Cyclomatic Complexity (Rob Allen) akrabat.com/slim-4-cyclom…
πŸ‘︎ 46
πŸ’¬︎
πŸ‘€︎ u/CensorVictim
πŸ“…︎ Apr 03 2019
🚨︎ report
On researching some wacky Cyclomatic Complexity scores in my code, I came across an epic flame-war over the treatment of ternary operators. 18 months and counting. github.com/pdepend/pdepen…
πŸ‘︎ 256
πŸ’¬︎
πŸ‘€︎ u/snobby_penguin
πŸ“…︎ Jan 23 2016
🚨︎ report
Cyclomatic complexity is really iffy

That is all.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/00rb
πŸ“…︎ Sep 16 2019
🚨︎ report
Thoughts on cyclomatic complexity in Golang's world medium.com/@DiegoZoracKy/…
πŸ‘︎ 23
πŸ’¬︎
πŸ‘€︎ u/DiegoZoracKy
πŸ“…︎ Apr 19 2018
🚨︎ report
Rubocop users - Cyclomatic and Perceived complexity, what limit do you use? Why?

I'm implementing Rubocop (with Rails) and I'm wondering what kind of advice you have for using these metrics?

The default value for Cyclomatic complexity is 6 and Perceived is 7. How do these guidelines translate to your projects?

Thanks!

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/ecoding5
πŸ“…︎ Aug 17 2015
🚨︎ report
Cyclomatic Complexity - Live Piano + Finger Drumming Performance youtu.be/_2AA9b9nV4k
πŸ‘︎ 7
πŸ’¬︎
πŸ‘€︎ u/Nular-Music
πŸ“…︎ Feb 04 2020
🚨︎ report
Thoughts on cyclomatic complexity in Golang's world medium.com/@DiegoZoracKy/…
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/DiegoZoracKy
πŸ“…︎ Apr 19 2018
🚨︎ report
WILT - Whitespace Integrated over Lines of Text (fast alternative to cyclomatic complexity checkers) github.com/ahungry/wilt
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/xenow
πŸ“…︎ Aug 22 2019
🚨︎ report
McCabe's Cyclomatic Complexity and Why We Don't Use It cqse.eu/en/blog/mccabe-cy…
πŸ‘︎ 54
πŸ’¬︎
πŸ‘€︎ u/nihathrael
πŸ“…︎ May 22 2014
🚨︎ report
Cyclomatic complexity by Thomas McCabe

I'm currently studying structure complexity and I came across McCabe's measurement for a program's complexity, where he uses only D-Diagrams (one input, one output) to calculate the complexity. It seems quite outdated and I was wondering how relevant this method is. Are there any more modern approaches for analyzing the strucutre complexity?

πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/dingenskirchen
πŸ“…︎ Feb 09 2017
🚨︎ report
Bluzelle expect a major code update in mid Oct, which will reflect the improvements in: build process, internal continuous integration, automated cyclomatic complexity checks, sprint development process. twitter.com/BluzelleHQ/st…
πŸ‘︎ 8
πŸ’¬︎
πŸ‘€︎ u/zzehdar
πŸ“…︎ Oct 03 2018
🚨︎ report
Code Coverage and Cyclomatic Complexity brianchang.info/2016/02/0…
πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/eviltoylet
πŸ“…︎ Feb 01 2016
🚨︎ report
On cyclomatic complexity

I'm working on a project that has a number of code quality tests [yay] built into its CI pipeline. One such test is for cyclomatic complexity.

The test currently ensures the cyclomatic complexity does not exceed 20. This seems absolutely ludicrous in my mind. It suggests poor programmers have constantly bumped the threshold to the point where they no longer have to worry about it.

I would like to suggest to them that they should lower the threshold to somewhere between 10-15, but would like some reassurance that others agree with my thoughts.

So, in your experience, what's the ideal threshold for cyclomatic complexity? Also, what's the highest you've ever seen?

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/paktsardines
πŸ“…︎ Nov 16 2018
🚨︎ report
Radon computes your code's complexity (Cyclomatic complexity) github.com/rubik/radon
πŸ‘︎ 76
πŸ’¬︎
πŸ‘€︎ u/rubik_
πŸ“…︎ Jan 10 2013
🚨︎ report
Lighthouse v0.6 for IDA Pro released! Intel pintool, cyclomatic complexity, batch load, bugfixes blog.ret2.io/2017/10/02/l…
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/TheUglyStranger
πŸ“…︎ Oct 02 2017
🚨︎ report
Relationship between Cyclomatic Complexity &amp; Software Testing testorigen.com/relationsh…
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/testorigen
πŸ“…︎ Dec 11 2017
🚨︎ report
Lighthouse v0.6 for IDA Pro released! Intel pintool, cyclomatic complexity, batch load, bugfixes blog.ret2.io/2017/10/02/l…
πŸ‘︎ 53
πŸ’¬︎
πŸ‘€︎ u/gaasedelen
πŸ“…︎ Oct 02 2017
🚨︎ report
Cyclomatic complexity for python code gdub.wordpress.com/2006/0…
πŸ‘︎ 7
πŸ’¬︎
πŸ‘€︎ u/motzer
πŸ“…︎ Jan 12 2007
🚨︎ report
Cyclomatic and NPath complexity explained (PHPMD) codingswag.com/2013/05/cy…
πŸ‘︎ 11
πŸ’¬︎
πŸ‘€︎ u/nerdklers
πŸ“…︎ May 22 2013
🚨︎ report
Cyclomatic Complexity: Logic in CSS csswizardry.com/2015/04/c…
πŸ‘︎ 2
πŸ’¬︎
πŸ“…︎ Apr 28 2015
🚨︎ report
Debunking Cyclomatic Complexity sdtimes.com/content/artic…
πŸ‘︎ 37
πŸ’¬︎
πŸ‘€︎ u/gst
πŸ“…︎ Mar 22 2008
🚨︎ report
Cyclomatic Complexity For Python Code gdub.wordpress.com/2006/0…
πŸ‘︎ 15
πŸ’¬︎
πŸ‘€︎ u/exeter
πŸ“…︎ Jun 19 2008
🚨︎ report
GCC Plugin: Compute cyclomatic complexity of functions based on the gcc internal representation github.com/ephox-gcc-plug…
πŸ‘︎ 9
πŸ’¬︎
πŸ‘€︎ u/perror
πŸ“…︎ Feb 18 2014
🚨︎ report
ELI5: What is Cyclomatic complexity?
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/levidurfee
πŸ“…︎ Nov 10 2016
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.