Cyclomatic Complexity

Cyclomatic Complexity

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

B3b2139e4f2c0eca4efe2379fcebc1c5?s=128

Anna Filina

October 08, 2016
Tweet

Transcript

  1. 2.

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

    { return 0; } return $this->standardShipping; } 2
  2. 3.

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

    { return 0; } return $this->standardShipping; } 3 Path 1 Path 2
  3. 7.

    Decision Branches 7 start product loop free shipping? end ◦

    Edges ◦ Nodes ◦ Connected components.
  4. 8.

    Decision Branches 8 start product loop free shipping? end ◦

    Edges ◦ Nodes ◦ Connected components.
  5. 9.

    Decision Branches 9 start product loop free shipping? end ◦

    Edges ◦ Nodes ◦ Connected components.
  6. 11.

    Zero Times foreach ($products as $product) { $total = $product->price

    * $product->quantity; } $tax = $total * ... 11
  7. 12.

    Multiple Times $total = 0; foreach ($products as $product) {

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

    Multiple Times $total = 0; foreach ($products as $product) {

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