cyclomatic_calculator.php 734 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. function process()
  3. {
  4. $language = isset($_REQUEST['language']) ? $_REQUEST['language'] : null;
  5. if(!$language)
  6. {
  7. return array("error" => "Language not requested. Please pass the GET parameter 'language'.");
  8. }
  9. if(isset($_POST['code']))
  10. {
  11. $code = $_POST['code'];
  12. if($_POST['code'] == '')
  13. {
  14. $code = "if(true) { echo 'hello'; }";
  15. }
  16. elseif(empty(trim($code)))
  17. {
  18. return array(
  19. "error" => "No code provided to analyze. Please pass the POST parameter 'code'.");
  20. }
  21. }
  22. switch (strtolower($language))
  23. {
  24. case 'php':
  25. include ("cc_php.php");
  26. break;
  27. default:
  28. return array("error" => "Language not supported.");
  29. }
  30. return array("value" => calculate($code));
  31. }
  32. echo json_encode(process());