File class.Authorization.php
has 580 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
define('AUTH_CREATE', 'create');
define('AUTH_EDIT', 'edit');
Function HasAuthority
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
public function HasAuthority($mundane_id, $type, $id, $role) {
logtrace("HasAuthority", array($mundane_id, $type, $id, $role));
if (valid_id($mundane_id) && (valid_id($id) || $type == AUTH_ADMIN)) {
;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function Authorize_h
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
public function Authorize_h($request) {
$response = array();
$this->mundane->clear();
if ($request['Token'] == null) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function Authorize_app
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
public function Authorize_app($request) {
$response = array();
if (trimlen($request['Token']) == 0) {
if (($app_id = $this->ApplicationIsAuthorized($request)) > 0) {
$this->app_auth->clear();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function RemoveAuthorization
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function RemoveAuthorization($request) {
logtrace('RemoveAuthorization', $request);
$response = array();
if (is_null($request['AuthorizationId']) || !$request['AuthorizationId'] > 0) {
$response = ProcessingError("AuthorizationId is not set.");
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Authorization
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class Authorization extends Ork3 {
public function __construct() {
parent::__construct();
$this->mundane = new yapo($this->db, DB_PREFIX . 'mundane');
Method HasAuthority
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function HasAuthority($mundane_id, $type, $id, $role) {
logtrace("HasAuthority", array($mundane_id, $type, $id, $role));
if (valid_id($mundane_id) && (valid_id($id) || $type == AUTH_ADMIN)) {
;
Method Authorize_h
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function Authorize_h($request) {
$response = array();
$this->mundane->clear();
if ($request['Token'] == null) {
Method Authorize_app
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function Authorize_app($request) {
$response = array();
if (trimlen($request['Token']) == 0) {
if (($app_id = $this->ApplicationIsAuthorized($request)) > 0) {
$this->app_auth->clear();
Function add_authorization
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function add_authorization($requester_id, $request) {
logtrace('add_authorization', $request);
$response = array();
switch ($request['Role']) {
case AUTH_CREATE: break;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method RemoveAuthorization
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function RemoveAuthorization($request) {
logtrace('RemoveAuthorization', $request);
$response = array();
if (is_null($request['AuthorizationId']) || !$request['AuthorizationId'] > 0) {
$response = ProcessingError("AuthorizationId is not set.");
Method GetApplicationRequests
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function GetApplicationRequests($request) {
$response = array('Status' => NoAuthorization(), 'ApplicationRequests' => array());
if (($requester_id = $this->IsAuthorized($request['Token'])) > 0) {
$sql = "select appauth.*, app.*, m.*
from " . DB_PREFIX . "application_auth appauth
Method ResetPassword
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function ResetPassword($request) {
$this->log->Write('Credential', 0, LOG_EDIT, array($request, $_SESSION, $_SERVER));
$response = array();
$this->mundane->clear();
$this->mundane->like('username', $request['UserName']);
Function IsAuthorized_app
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function IsAuthorized_app($token) {
logtrace("IsAuthorized_app($token)", null);
if (strlen($token) == 32) return 0;
$this->app_auth->clear();
$this->app_auth->token = $token;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function SaltPassword
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function SaltPassword($salt, $password, $timestamp, $reset = 0) {
global $DB;
if ($reset) {
$resetrequest = 1;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
default: return false;
Avoid too many return
statements within this method. Open
if ($sufficient) return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
if ($this->HasAuthority($mundane_id, AUTH_KINGDOM, $event->kingdom_id, $role) || $this->HasAuthority($mundane_id, AUTH_PARK, $event->park_id, $role) || $event->mundane_id = $mundane_id) return true;
Avoid too many return
statements within this method. Open
if ($this->HasAuthority($mundane_id, AUTH_KINGDOM, $id, $role)) return true;
Avoid too many return
statements within this method. Open
return $sufficient;
Avoid too many return
statements within this method. Open
case AUTH_ADMIN: return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return 0;
Avoid too many return
statements within this method. Open
return 0;
Avoid too many return
statements within this method. Open
case AUTH_CREATE: return true;
Function SetApplicationAuthorization
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function SetApplicationAuthorization($request) {
if (($requester_id = $this->IsAuthorized($request['Token'])) > 0) {
$this->app_auth->clear();
$this->app_auth->application_auth_id = $request['ApplicationAuthorizationId'];
$this->app_auth->mundane_id = $requester_id;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function add_auth_h
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function add_auth_h($request) {
logtrace('add_auth_h', $request);
$this->auth->clear();
$this->auth->mundane_id = $request['MundaneId'];
switch ($request['Type']) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function IsAuthorized_h
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function IsAuthorized_h($token) {
if (isset($_SESSION['is_authorized_mundane_id']))
return $_SESSION['is_authorized_mundane_id'];
logtrace("IsAuthorized_h($token)", null);
if (strlen($token) != 32) return 0;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Identical blocks of code found in 2 locations. Consider refactoring. Open
} else {
$this->app_auth->token = md5(openssl_random_pseudo_bytes(16) . microtime());
$this->app_auth->token_expires = date('c', time() + LOGIN_TIMEOUT);
$this->app_auth->save();
$response['Status'] = Success();
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 134.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
} else if (strtotime($this->mundane->token_expires) > time()) {
$this->app_auth->token = md5(openssl_random_pseudo_bytes(16) . microtime());
$this->app_auth->token_expires = date('c', time() + LOGIN_TIMEOUT);
$this->app_auth->save();
$response['Status'] = Success();
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 134.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76