Don’t write unnecessary tests anymore. Use a simple, scientific approach.
foolab.ca | @foolabcaCyclomatic ComplexityBulgaria PHP, Sofia - October 8, 2016
View Slide
Execution Pathspublic function getShipping(){if ($this->subtotal >= 40) {return 0;}return $this->standardShipping;}2
Execution Pathspublic function getShipping(){if ($this->subtotal >= 40) {return 0;}return $this->standardShipping;}3Path 1Path 2
Decision Branches4startproduct loopfree shipping?end
Decision Branches5startproduct loopfree shipping?end
Cyclomatic complexity =edges − nodes + 2 * connected components
Decision Branches7startproduct loopfree shipping?end◦ Edges◦ Nodes◦ Connected components.
Decision Branches8startproduct loopfree shipping?end◦ Edges◦ Nodes◦ Connected components.
Decision Branches9startproduct loopfree shipping?end◦ Edges◦ Nodes◦ Connected components.
Cyclomatic complexity =9 − 8 + 2 * 1 =3
Zero Timesforeach ($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