cc_php.php 441 B

1234567891011121314151617181920212223242526
  1. <?php
  2. function calculate($code)
  3. {
  4. $complexity = 1;
  5. $decisionPoints = array(
  6. "case",
  7. "default",
  8. "catch",
  9. "if",
  10. "for",
  11. "foreach",
  12. "while",
  13. "do",
  14. "elseif"
  15. );
  16. $regexPoints = array();
  17. foreach ($decisionPoints as $token)
  18. {
  19. $regexPoints[] = "\b$token\b";
  20. }
  21. preg_match_all("/" . implode('|', $regexPoints) . "/", $code, $matches, PREG_OFFSET_CAPTURE);
  22. $complexity += count($matches[0]);
  23. return $complexity;
  24. }