Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Cyclomatic Complexity
Search
Anna Filina
PRO
October 08, 2016
Programming
0
250
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
Semi-Automated Refactoring and Upgrades with Rector
afilina
PRO
0
73
Better Code Design in PHP
afilina
PRO
1
490
Effortless Software Development
afilina
PRO
1
200
Writing Testable Symfony Apps
afilina
PRO
0
260
Upgrading Legacy to the Latest PHP Version
afilina
PRO
0
260
Avoid Costly Framework Upgrades
afilina
PRO
2
1.5k
Fantastic Bugs and How to Avoid Them
afilina
PRO
1
970
Adding Tests to Untestable Legacy Code
afilina
PRO
4
1k
You Don't Need More Developers
afilina
PRO
5
1.4k
Other Decks in Programming
See All in Programming
SwiftUI Performance 不要なViewの再描画と更新を抑える
bigamitiongit
1
150
受託開発でGitLab CI を活用していく
xiombatsg
1
270
VSCodeでのDatabricks開発もお勧めしたい/I would also recommend Databricks development with VSCode.
kazumain
0
240
Ruby Function Composition
bkuhlmann
1
330
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
22
15k
雑に思考を整理する技術と効能
konifar
55
25k
両面どころかインフラもTSでできるよ ~ 全方位TypeScriptによるプロダクト開発 ~
myfinder
9
3.2k
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
880
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.2k
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
480
Ruby Pattern Matching
bkuhlmann
0
920
脱・初心者!脱・マネコン!AWS CDKを使ってみませんか!?
har1101
0
300
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
397
65k
Visualization
eitanlees
135
14k
Art, The Web, and Tiny UX
lynnandtonic
288
19k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
20
1.6k
Clear Off the Table
cherdarchuk
83
310k
A Tale of Four Properties
chriscoyier
150
22k
Automating Front-end Workflow
addyosmani
1355
200k
The Cult of Friendly URLs
andyhume
74
5.7k
Debugging Ruby Performance
tmm1
70
11k
Building Adaptive Systems
keathley
30
1.8k
A Philosophy of Restraint
colly
196
16k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
273
13k
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