OmarElGabry/miniPHP

View on GitHub
app/models/Validation.php

Summary

Maintainability
D
2 days
Test Coverage

Validation has 34 functions (exceeds 20 allowed). Consider refactoring.
Open

class Validation {

    /**
     * validation errors
     *
Severity: Minor
Found in app/models/Validation.php - About 4 hrs to fix

    Function validate has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        public function validate($data, $skip = false){
    
            $passed = true;
    
            foreach($data as $placeholder => $rules){
    Severity: Minor
    Found in app/models/Validation.php - About 4 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

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

      Function addError has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          private function addError($rule, $placeholder, $value, $args = []){
      
              if(isset($this->ruleMessages[$rule])){
                  $this->errors[] = $this->ruleMessages[$rule];
              }
      Severity: Minor
      Found in app/models/Validation.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 validate has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function validate($data, $skip = false){
      
              $passed = true;
      
              foreach($data as $placeholder => $rules){
      Severity: Minor
      Found in app/models/Validation.php - About 1 hr to fix

        Method defaultMessages has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function defaultMessages($rule){
                $messages = [
                    "required" => "{placeholder} can't be empty",
                    "minLen"   => "{placeholder} can't be less than {0} character",
                    "maxLen"   => "{placeholder} can't be greater than {0} character",
        Severity: Minor
        Found in app/models/Validation.php - About 1 hr to fix

          Function emailUnique has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              private function emailUnique($email){
          
                  $database = Database::openConnection();
          
                  // email is unique in the database, So, we can't have more than 2 same emails
          Severity: Minor
          Found in app/models/Validation.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

          Avoid too many return statements within this method.
          Open

                  return false;
          Severity: Major
          Found in app/models/Validation.php - About 30 mins to fix

            Function inArray has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                private function inArray($value, $arr){
            
                    if(is_array($value)){
                        foreach($value as $val){
                            if(!in_array($val, $arr, true)){
            Severity: Minor
            Found in app/models/Validation.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

            There are no issues that match your filters.

            Category
            Status