$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Cyclomatic Complexity
Search
Anna Filina
October 08, 2016
Programming
0
280
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
Surviving a Symfony Upgrade
afilina
0
77
Upgrading Legacy to the Latest PHP Version
afilina
1
150
Better Code Design in PHP
afilina
0
270
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
170
Better Code Design in PHP
afilina
1
430
Better Code Design in PHP
afilina
0
590
Adding Tests to Untestable Legacy Code
afilina
0
370
Upgrading Legacy to the Latest PHP Version
afilina
0
380
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
290
Other Decks in Programming
See All in Programming
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
11
11k
DSPy Meetup Tokyo #1 - はじめてのDSPy
masahiro_nishimi
1
170
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
160
テストやOSS開発に役立つSetup PHP Action
matsuo_atsushi
0
150
Integrating WordPress and Symfony
alexandresalome
0
150
配送計画の均等化機能を提供する取り組みについて(⽩⾦鉱業 Meetup Vol.21@六本⽊(数理最適化編))
izu_nori
0
150
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
160
著者と進める!『AIと個人開発したくなったらまずCursorで要件定義だ!』
yasunacoffee
0
140
tparseでgo testの出力を見やすくする
utgwkk
2
220
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
340
JETLS.jl ─ A New Language Server for Julia
abap34
1
400
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.4k
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
The Cult of Friendly URLs
andyhume
79
6.7k
Facilitating Awesome Meetings
lara
57
6.7k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Docker and Python
trallard
47
3.7k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.2k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Rails Girls Zürich Keynote
gr2m
95
14k
Thoughts on Productivity
jonyablonski
73
5k
Side Projects
sachag
455
43k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
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