amtgard/ORK3

View on GitHub
system/lib/ork3/class.Authorization.php

Summary

Maintainability
F
1 wk
Test Coverage

File class.Authorization.php has 580 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

define('AUTH_CREATE', 'create');
define('AUTH_EDIT', 'edit');

Severity: Major
Found in system/lib/ork3/class.Authorization.php - About 1 day to fix

    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)) {
                ;
    Severity: Minor
    Found in system/lib/ork3/class.Authorization.php - About 6 hrs to fix

    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) {
    Severity: Minor
    Found in system/lib/ork3/class.Authorization.php - About 5 hrs to fix

    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();
    Severity: Minor
    Found in system/lib/ork3/class.Authorization.php - About 5 hrs to fix

    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.");
    Severity: Minor
    Found in system/lib/ork3/class.Authorization.php - About 3 hrs to fix

    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');
    Severity: Minor
    Found in system/lib/ork3/class.Authorization.php - About 3 hrs to fix

      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)) {
                  ;
      Severity: Major
      Found in system/lib/ork3/class.Authorization.php - About 2 hrs to fix

        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) {
        Severity: Major
        Found in system/lib/ork3/class.Authorization.php - About 2 hrs to fix

          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();
          Severity: Major
          Found in system/lib/ork3/class.Authorization.php - About 2 hrs to fix

            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;
            Severity: Minor
            Found in system/lib/ork3/class.Authorization.php - About 1 hr to fix

            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.");
            Severity: Minor
            Found in system/lib/ork3/class.Authorization.php - About 1 hr to fix

              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
              Severity: Minor
              Found in system/lib/ork3/class.Authorization.php - About 1 hr to fix

                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']);
                Severity: Minor
                Found in system/lib/ork3/class.Authorization.php - About 1 hr to fix

                  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;
                  Severity: Minor
                  Found in system/lib/ork3/class.Authorization.php - About 45 mins to fix

                  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;
                  Severity: Minor
                  Found in system/lib/ork3/class.Authorization.php - About 35 mins to fix

                  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;
                  Severity: Major
                  Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                if ($sufficient) return true;
                    Severity: Major
                    Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return false;
                      Severity: Major
                      Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                        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;
                        Severity: Major
                        Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                                  if ($this->HasAuthority($mundane_id, AUTH_KINGDOM, $id, $role)) return true;
                          Severity: Major
                          Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return $sufficient;
                            Severity: Major
                            Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                  case AUTH_ADMIN: return true;
                              Severity: Major
                              Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return false;
                                Severity: Major
                                Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return 0;
                                  Severity: Major
                                  Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                            return 0;
                                    Severity: Major
                                    Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          case AUTH_CREATE: return true;
                                      Severity: Major
                                      Found in system/lib/ork3/class.Authorization.php - About 30 mins to fix

                                        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;
                                        Severity: Minor
                                        Found in system/lib/ork3/class.Authorization.php - About 25 mins to fix

                                        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']) {
                                        Severity: Minor
                                        Found in system/lib/ork3/class.Authorization.php - About 25 mins to fix

                                        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;
                                        Severity: Minor
                                        Found in system/lib/ork3/class.Authorization.php - About 25 mins to fix

                                        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();
                                        Severity: Major
                                        Found in system/lib/ork3/class.Authorization.php and 1 other location - About 2 hrs to fix
                                        system/lib/ork3/class.Authorization.php on lines 279..290

                                        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

                                        Further Reading

                                        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();
                                        Severity: Major
                                        Found in system/lib/ork3/class.Authorization.php and 1 other location - About 2 hrs to fix
                                        system/lib/ork3/class.Authorization.php on lines 251..259

                                        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

                                        Further Reading

                                        There are no issues that match your filters.

                                        Category
                                        Status