Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cyclomatic Complexity

Cyclomatic Complexity

Don’t write unnecessary tests anymore. Use a simple, scientific approach.

Anna Filina

October 08, 2016
Tweet

More Decks by Anna Filina

Other Decks in Programming

Transcript

  1. Execution Paths public function getShipping() { if ($this->subtotal >= 40)

    { return 0; } return $this->standardShipping; } 2
  2. Execution Paths public function getShipping() { if ($this->subtotal >= 40)

    { return 0; } return $this->standardShipping; } 3 Path 1 Path 2
  3. Decision Branches 7 start product loop free shipping? end ◦

    Edges ◦ Nodes ◦ Connected components.
  4. Decision Branches 8 start product loop free shipping? end ◦

    Edges ◦ Nodes ◦ Connected components.
  5. Decision Branches 9 start product loop free shipping? end ◦

    Edges ◦ Nodes ◦ Connected components.
  6. Zero Times foreach ($products as $product) { $total = $product->price

    * $product->quantity; } $tax = $total * ... 11
  7. Multiple Times $total = 0; foreach ($products as $product) {

    $total = $product->price * $product->quantity; } $tax = $total * ... 12
  8. Multiple Times $total = 0; foreach ($products as $product) {

    $total += $product->price * $product->quantity; } $tax = $total * ... 13