functions/admintools.php
<?php/** * * @param string $config The config * @param int $acctype ID of user to check * @return string The account type * * @author Jonas H�sser * * @SuppressWarnings(PHPMD.ElseExpression) * * @since 0.4 */Function `getAccountType` has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. function getAccountType($config, $acctype){ //init array $usertype = (object) array(); switch($acctype){ case 0: $type = $config->app_vocabulary['baned']; break; case 1: $type = $config->app_vocabulary['jodler']; break; case 2: $type = $config->app_vocabulary['mod']; break; case 3: $type = $config->app_vocabulary['admin']; break; case 4: $type = $config->app_vocabulary['superadmin']; break; default: $type = $config->app_vocabulary['baned']; } $usertype->typeID = $acctype; $usertype->typedesc = $type; return $usertype; } /** * * @param string $config The config * @param string $content post or comment * @param int $contentID ID of post or comment * @param int $reason Reason of reporting * @return mixed ID of report or null if failed * * @author Jonas Hüsser * * @SuppressWarnings(PHPMD.ElseExpression) * * @since 0.5 */Method `reportContent` has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Function `reportContent` has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. function reportContent( $content, $contentID, $reason){ global $apiroot; $userid = $_SESSION['userid'];Similar blocks of code found in 2 locations. Consider refactoring. if($content == "post"){ $postfields = "{\n \n \"abuseIDFK\": \"$reason\",\n \"jodelDFK\": \"$contentID\"\n,\n \"jodlerIDFK\": \"$userid\"\n}"; $callurl = $apiroot . "jodels?filter=jodelID,eq," . $contentID . "&transform=1"; $jodeljson = getCall($callurl); $scores = json_decode($jodeljson, true); foreach($scores['jodels'] as $jodelscore){ $score = $jodelscore['score']; }Avoid using undefined variables such as '$config' which will lead to PHP notices. $newscore = $score - $config->postmeta['get_report']; $callurl = $apiroot . "jodels/" . $contentID; $putfields = "{\n \n \"score\": \"$newscore\"\n \n}";Avoid unused local variables such as '$scoreupdate'. $scoreupdate = putCall($callurl, $putfields); Similar blocks of code found in 2 locations. Consider refactoring. } elseif($content == "comment"){ $postfields = "{\n \n \"abuseIDFK\": \"$reason\",\n \"commentIDFK\": \"$contentID\"\n,\n \"jodlerIDFK\": \"$userid\"\n}"; $callurl = $apiroot . "comments?filter=commentID,eq," . $contentID . "&transform=1"; $commentjson = getCall($callurl); $scores = json_decode($commentjson, true); foreach($scores['comments'] as $commentscore){ $score = $commentscore['score']; }Avoid using undefined variables such as '$config' which will lead to PHP notices. $newscore = $score - $config->postmeta['get_report']; $callurl = $apiroot . "comments/" . $contentID; $putfields = "{\n \n \"score\": \"$newscore\"\n \n}"; $scoreupdate = putCall($callurl, $putfields); } $callurl = $apiroot . "reports"; $resp = postCall($callurl, $postfields); return $resp; }