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
October 08, 2016
Programming
0
270
Cyclomatic Complexity
Don’t write unnecessary tests anymore. Use a simple, scientific approach.
Anna Filina
October 08, 2016
Tweet
Share
More Decks by Anna Filina
See All by Anna Filina
Better Code Design in PHP
afilina
0
210
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
120
Better Code Design in PHP
afilina
0
320
Better Code Design in PHP
afilina
0
500
Adding Tests to Untestable Legacy Code
afilina
0
330
Upgrading Legacy to the Latest PHP Version
afilina
0
340
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
230
Better Code Design in PHP
afilina
1
700
Effortless Software Development
afilina
1
300
Other Decks in Programming
See All in Programming
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
120
AI Agentを利用したAndroid開発について
yuchan2215
0
200
今から始めるCursor / Windsurf / Cline
kengo_hayano
0
110
Gunma.web #55
tinykitten
0
130
アーキテクトと美学 / Architecture and Aesthetics
nrslib
12
2.9k
SLI/SLOの設定を進めるその前に アラート品質の改善に取り組んだ話
tanden
2
660
PHPUnit 高速化テクニック / PHPUnit Speedup Techniques
pinkumohikan
1
1.1k
RubyKaigiで手に入れた HHKB Studioのための HIDRawドライバ
iberianpig
0
190
リアクティブシステムの変遷から理解するalien-signals / Learning alien-signals from the evolution of reactive systems
yamanoku
2
720
Going Structural with Named Tuples
bishabosha
0
150
php-fpm がリクエスト処理する仕組みを追う / Tracing-How-php-fpm-Handles-Requests
shin1x1
4
770
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
290
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Being A Developer After 40
akosma
90
590k
Testing 201, or: Great Expectations
jmmastey
42
7.4k
The Cost Of JavaScript in 2023
addyosmani
48
7.6k
Designing Experiences People Love
moore
140
23k
Optimizing for Happiness
mojombo
377
70k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.5k
Navigating Team Friction
lara
183
15k
Practical Orchestrator
shlominoach
186
10k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
GraphQLとの向き合い方2022年版
quramy
45
14k
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