OmarElGabry/miniPHP

View on GitHub

Showing 119 of 119 total issues

Function alphaID has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    public static function alphaID($in, $to_num = false, $pad_up = false, $pass_key = null) {
        $out = '';
        $index = 'abcdefghijklmnopqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $base = strlen($index);

Severity: Minor
Found in app/core/Encryption.php - About 2 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

Request has 25 functions (exceeds 20 allowed). Consider refactoring.
Open

class Request{

    /**
     * Set a list of trusted hosts patterns.
     * 
Severity: Minor
Found in app/core/Request.php - About 2 hrs to fix

    File Validation.php has 276 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /**
     * Validation class
     *
    Severity: Minor
    Found in app/models/Validation.php - About 2 hrs to fix

      Function triggerComponents has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          private function triggerComponents(){
      
              // You need to Fire the Components and Controller callbacks in the correct orde
              // For example, Authorization depends on form element, so you need to trigger Security first.
      
      
      Severity: Minor
      Found in app/core/Controller.php - About 2 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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          <?php if(empty($comments)){ ?>
              <li class='no-data'><div class='text-center'><span class='text-muted'>There is no comments!</span></div></li>
          
          <?php } else{
                  foreach($comments as $comment){?>
      Severity: Major
      Found in app/views/posts/comments.php and 1 other location - About 2 hrs to fix
      app/views/newsfeed/newsfeed.php on lines 2..26

      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 131.

      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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          <?php if(empty($newsfeed)){ ?>
              <li class='no-data text-center'><span class='text-muted'>There is no news feed!!</span></li>
          
          <?php } else{
                  foreach($newsfeed as $feed){?>
      Severity: Major
      Found in app/views/newsfeed/newsfeed.php and 1 other location - About 2 hrs to fix
      app/views/posts/comments.php on lines 3..29

      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 131.

      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

      Function isEmpty has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          private function isEmpty($value){
      
              if(is_null($value)) {
                  return true;
              }
      Severity: Minor
      Found in app/models/Validation.php - About 2 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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                  $("#link-register").click(function() {
                      
                      $("#form-login, #form-forgot-password").addClass("display-none");
                      $("#form-register").removeClass("display-none");
                      $(".panel-title").text("Register");
      Severity: Major
      Found in public/js/main.js and 1 other location - About 2 hrs to fix
      public/js/main.js on lines 521..527

      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 79.

      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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                  $("#form-register #link-login").click(function() {
                      
                      $(".panel-title").text("Login");
                      $("#form-register").addClass("display-none");
                      $("#form-login").removeClass("display-none");
      Severity: Major
      Found in public/js/main.js and 1 other location - About 2 hrs to fix
      public/js/main.js on lines 513..519

      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 79.

      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

      Function updateProfileInfo has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          public function updateProfileInfo($userId, $name, $password, $email, $confirmEmail){
      
              $database = Database::openConnection();
              $curUser = $this->getProfileInfo($userId);
      
      
      Severity: Minor
      Found in app/models/User.php - About 2 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

      Method updateProfileInfo has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function updateProfileInfo($userId, $name, $password, $email, $confirmEmail){
      
              $database = Database::openConnection();
              $curUser = $this->getProfileInfo($userId);
      
      
      Severity: Major
      Found in app/models/User.php - About 2 hrs to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function getUpdateForm(){
        
                $commentId = Encryption::decryptIdWithDash($this->request->data("comment_id"));
        
                if(!$this->comment->exists($commentId)){
        Severity: Major
        Found in app/controllers/CommentsController.php and 1 other location - About 2 hrs to fix
        app/controllers/NewsFeedController.php on lines 65..77

        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 121.

        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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function getUpdateForm(){
        
                $newsfeedId = Encryption::decryptIdWithDash($this->request->data("newsfeed_id"));
        
                if(!$this->newsfeed->exists($newsfeedId)){
        Severity: Major
        Found in app/controllers/NewsFeedController.php and 1 other location - About 2 hrs to fix
        app/controllers/CommentsController.php on lines 83..95

        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 121.

        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

        Function validateData has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            validateData: function (result, targetBlock, errorFunc, errorType, returnVal){
        
                // 1. clear all existing error or success messages
                helpers.clearMessages(targetBlock);
        
        
        Severity: Minor
        Found in public/js/main.js - 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

        Function deny has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function deny($role, $resource, $actions = "*"){
        
                $actions = array_map("strtolower", (array)$actions);
        
                foreach(self::$perms as $key => &$perm){
        Severity: Minor
        Found in app/models/Permission.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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function getById(){
        
                $newsfeedId = Encryption::decryptIdWithDash($this->request->data("newsfeed_id"));
        
                if(!$this->newsfeed->exists($newsfeedId)){
        Severity: Major
        Found in app/controllers/NewsFeedController.php and 1 other location - About 1 hr to fix
        app/controllers/CommentsController.php on lines 125..137

        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 117.

        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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function getById(){
        
                $commentId = Encryption::decryptIdWithDash($this->request->data("comment_id"));
        
                if(!$this->comment->exists($commentId)){
        Severity: Major
        Found in app/controllers/CommentsController.php and 1 other location - About 1 hr to fix
        app/controllers/NewsFeedController.php on lines 99..111

        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 117.

        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

        Function updateUserInfo has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function updateUserInfo($userId, $adminId, $name, $password, $role){
        
                 $user = $this->getProfileInfo($userId);
        
                 $name = (!empty($name) && $name !== $user["name"])? $name: null;
        Severity: Minor
        Found in app/models/Admin.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

        Function run has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function run(){
        
                // split the requested URL
                $this->splitUrl();
        
        
        Severity: Minor
        Found in app/core/App.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 doLogIn has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function doLogIn($email, $password, $rememberMe, $userIp, $userAgent){
        
                // 1. check if user is blocked
                if($this->isIpBlocked($userIp)) {
                    $this->errors[] = "Your IP Address has been blocked";
        Severity: Minor
        Found in app/models/Login.php - About 1 hr to fix
          Severity
          Category
          Status
          Source
          Language