| @@ 21-52 (lines=32) @@ | ||
| 18 | /** |
|
| 19 | * Test function with a high cyclomatic complexity |
|
| 20 | */ |
|
| 21 | function ccn_function($arg) |
|
| 22 | { |
|
| 23 | switch ($arg) { |
|
| 24 | case 1: |
|
| 25 | for ($i = 0; $i < 10; ++$i) { |
|
| 26 | if ($i % 2 === 0) { |
|
| 27 | if ($arg - $i < 0) { |
|
| 28 | echo "foo"; |
|
| 29 | } |
|
| 30 | } |
|
| 31 | } |
|
| 32 | break; |
|
| 33 | case 2: |
|
| 34 | while (true) { |
|
| 35 | if (time() % 5 === 0 && time() % 2 === 0) { |
|
| 36 | break; |
|
| 37 | } else { |
|
| 38 | if (time() % 7 === 0) { |
|
| 39 | $x = true; |
|
| 40 | for ($i = 0; $i < 42; ++$i) { |
|
| 41 | $x = $x || true; |
|
| 42 | } |
|
| 43 | ||
| 44 | return $x; |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||
| 48 | return 23; |
|
| 49 | } |
|
| 50 | break; |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||
| @@ 23-54 (lines=32) @@ | ||
| 20 | * |
|
| 21 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
|
| 22 | */ |
|
| 23 | function ccn_function($arg) |
|
| 24 | { |
|
| 25 | switch ($arg) { |
|
| 26 | case 1: |
|
| 27 | for ($i = 0; $i < 10; ++$i) { |
|
| 28 | if ($i % 2 === 0) { |
|
| 29 | if ($arg - $i < 0) { |
|
| 30 | echo "foo"; |
|
| 31 | } |
|
| 32 | } |
|
| 33 | } |
|
| 34 | break; |
|
| 35 | case 2: |
|
| 36 | while (true) { |
|
| 37 | if (time() % 5 === 0 && time() % 2 === 0) { |
|
| 38 | break; |
|
| 39 | } else { |
|
| 40 | if (time() % 7 === 0) { |
|
| 41 | $x = true; |
|
| 42 | for ($i = 0; $i < 42; ++$i) { |
|
| 43 | $x = $x || true; |
|
| 44 | } |
|
| 45 | ||
| 46 | return $x; |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||
| 50 | return 23; |
|
| 51 | } |
|
| 52 | break; |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||