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
210
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
afilina
PRO
0
150
afilina
PRO
0
200
afilina
PRO
1
130
afilina
PRO
1
140
afilina
PRO
3
110
afilina
PRO
3
330
afilina
PRO
2
200
afilina
PRO
2
65
afilina
PRO
1
27
Other Decks in Programming
See All in Programming
osyo
1
370
kenmaz
1
100
yokaze
0
470
wasabeef
1
580
zsmb
2
110
azdaroth
0
100
brunopulis
1
100
inoue2002
0
290
akatsukinewgrad
0
220
kgmyshin
1
260
mraible
PRO
0
320
siketyan
1
120
Featured
See All Featured
chriscoyier
499
130k
lara
172
9.5k
cromwellryan
101
5.9k
jeffersonlam
328
15k
brad_frost
156
6.4k
marcelosomers
220
15k
danielanewman
1
480
addyosmani
1347
190k
malarkey
192
8.6k
keathley
18
650
pedronauck
652
110k
orderedlist
PRO
329
35k
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