Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Cyclomatic Complexity
Anna Filina
PRO
October 08, 2016
Programming
0
240
Cyclomatic Complexity
Don’t write unnecessary tests anymore. Use a simple, scientific approach.
Anna Filina
PRO
October 08, 2016
Tweet
Share
More Decks by Anna Filina
See All by Anna Filina
Writing Testable Symfony Apps
afilina
PRO
0
78
Upgrading Legacy to the Latest PHP Version
afilina
PRO
0
140
Avoid Costly Framework Upgrades
afilina
PRO
2
1.3k
Fantastic Bugs and How to Avoid Them
afilina
PRO
1
780
Adding Tests to Untestable Legacy Code
afilina
PRO
4
850
You Don't Need More Developers
afilina
PRO
5
1.2k
Fantastic Bugs and How to Avoid Them
afilina
PRO
0
170
Ship 10 Times Faster With These Designs
afilina
PRO
0
420
Effortless Software Development
afilina
PRO
1
380
Other Decks in Programming
See All in Programming
はてなリモートインターンシップ2022 インフラ 講義資料
hatena
4
2.1k
PHPアプリケーションにおけるアーキテクチャメトリクスについて / Architecture Metrics in PHP Applications
isanasan
1
210
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
2
42k
Swift Concurrency in GoodNotes
inamiy
4
1.3k
Qiita Night PHP 2023
fuwasegu
0
830
Milestoner
bkuhlmann
1
240
OSSから学んだPR Descriptionの書き方
fugakkbn
4
120
ちょうぜつ改め21世紀ふつうのソフトウェア設計
tanakahisateru
7
6k
花き業界のサプライチェーンを繋げるプロダクト開発の進め方
userlike1
0
100
監視せなあかんし、五大紙だけにオオカミってな🐺🐺🐺🐺🐺
sadnessojisan
2
1.2k
Micro Frontends with Module Federation @MicroFrontend Summit 2023
manfredsteyer
PRO
0
430
Prácticas de Seguridad en Kubernetes
pablokbs
0
110
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
284
18k
Producing Creativity
orderedlist
PRO
335
37k
The Invisible Customer
myddelton
113
12k
BBQ
matthewcrist
75
8.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
217
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
500
130k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
351
21k
Documentation Writing (for coders)
carmenintech
51
2.9k
Why Our Code Smells
bkeepers
PRO
326
55k
Creatively Recalculating Your Daily Design Routine
revolveconf
207
11k
No one is an island. Learnings from fostering a developers community.
thoeni
12
1.5k
Typedesign – Prime Four
hannesfritz
34
1.5k
Transcript
foolab.ca | @foolabca Cyclomatic Complexity Bulgaria PHP, Sofia - October
8, 2016
Execution Paths public function getShipping() { if ($this->subtotal >= 40)
{ return 0; } return $this->standardShipping; } 2
Execution Paths public function getShipping() { if ($this->subtotal >= 40)
{ return 0; } return $this->standardShipping; } 3 Path 1 Path 2
Decision Branches 4 start product loop free shipping? end
Decision Branches 5 start product loop free shipping? end
Cyclomatic complexity = edges − nodes + 2 * connected
components
Decision Branches 7 start product loop free shipping? end ◦
Edges ◦ Nodes ◦ Connected components.
Decision Branches 8 start product loop free shipping? end ◦
Edges ◦ Nodes ◦ Connected components.
Decision Branches 9 start product loop free shipping? end ◦
Edges ◦ Nodes ◦ Connected components.
Cyclomatic complexity = 9 − 8 + 2 * 1
= 3
Zero Times foreach ($products as $product) { $total = $product->price
* $product->quantity; } $tax = $total * ... 11
Multiple Times $total = 0; foreach ($products as $product) {
$total = $product->price * $product->quantity; } $tax = $total * ... 12
Multiple Times $total = 0; foreach ($products as $product) {
$total += $product->price * $product->quantity; } $tax = $total * ... 13
@afilina afilina.com