1234567891011121314151617181920212223242526 |
- <?php
- function calculate($code)
- {
- $complexity = 1;
- $decisionPoints = array(
- "case",
- "default",
- "catch",
- "if",
- "for",
- "foreach",
- "while",
- "do",
- "elseif"
- );
- $regexPoints = array();
- foreach ($decisionPoints as $token)
- {
- $regexPoints[] = "\b$token\b";
- }
- preg_match_all("/" . implode('|', $regexPoints) . "/", $code, $matches, PREG_OFFSET_CAPTURE);
- $complexity += count($matches[0]);
- return $complexity;
- }
|