plugins/sys/classes/yf_model.class.php

Summary

Maintainability
F
3 days
Test Coverage

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

<?php

load('yf_model_result', '', 'classes/model/');
load('yf_model_relation', '', 'classes/model/');

Severity: Minor
Found in plugins/sys/classes/yf_model.class.php - About 7 hrs to fix

    yf_model has 53 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class yf_model
    {
        const CREATED_AT = 'created_at';
        const UPDATED_AT = 'updated_at';
    
    
    Severity: Major
    Found in plugins/sys/classes/yf_model.class.php - About 7 hrs to fix

      Method new_query has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function new_query($params = [])
          {
              if ($params['where'] === null) {
                  unset($params['where']);
              }
      Severity: Minor
      Found in plugins/sys/classes/yf_model.class.php - About 1 hr to fix

        Function __call has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            public function __call($name, $args)
            {
                $where_prefix = 'where_';
                $scope_prefix = 'scope_';
                $get_prefix = 'get_attr_';
        Severity: Minor
        Found in plugins/sys/classes/yf_model.class.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 new_query has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            public function new_query($params = [])
            {
                if ($params['where'] === null) {
                    unset($params['where']);
                }
        Severity: Minor
        Found in plugins/sys/classes/yf_model.class.php - About 55 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

        Method belongs_to_many has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            public function belongs_to_many($related, $pivot_table = null, $foreign_key = null, $other_key = null, $relation = null)
        Severity: Minor
        Found in plugins/sys/classes/yf_model.class.php - About 35 mins to fix

          Method has_many_through has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function has_many_through($related, $through_model, $foreign_key = null, $local_key = null, $relation = null)
          Severity: Minor
          Found in plugins/sys/classes/yf_model.class.php - About 35 mins to fix

            Function set has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function set($name, $value = null)
                {
                    if (is_array($name)) {
                        $func = __FUNCTION__;
                        foreach ($name as $k => $v) {
            Severity: Minor
            Found in plugins/sys/classes/yf_model.class.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

                    return main()->extend_call($this, $name, $args);
            Severity: Major
            Found in plugins/sys/classes/yf_model.class.php - About 30 mins to fix

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

                  public function set_data($data = [])
                  {
                      if ($data instanceof yf_model_result) {
                          $data = $data->get_data();
                      }
              Severity: Minor
              Found in plugins/sys/classes/yf_model.class.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

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

                  public function has_one($related, $foreign_key = null, $local_key = null, $relation = null)
                  {
                      if ($relation === null) {
                          list(, $caller) = debug_backtrace(false);
                          $relation = $caller['function'];
              Severity: Major
              Found in plugins/sys/classes/yf_model.class.php and 1 other location - About 3 hrs to fix
              plugins/sys/classes/yf_model.class.php on lines 554..569

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

              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 has_many($related, $foreign_key = null, $local_key = null, $relation = null)
                  {
                      if ($relation === null) {
                          list(, $caller) = debug_backtrace(false);
                          $relation = $caller['function'];
              Severity: Major
              Found in plugins/sys/classes/yf_model.class.php and 1 other location - About 3 hrs to fix
              plugins/sys/classes/yf_model.class.php on lines 506..521

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

              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 static function first_or_create()
                  {
                      $obj = isset($this) ? $this : new static();
                      $args = func_get_args();
                      $first = $obj->new_query([
              Severity: Major
              Found in plugins/sys/classes/yf_model.class.php and 1 other location - About 1 hr to fix
              plugins/sys/classes/yf_model.class.php on lines 118..132

              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 static function first_or_new()
                  {
                      $obj = isset($this) ? $this : new static();
                      $args = func_get_args();
                      $first = $obj->new_query([
              Severity: Major
              Found in plugins/sys/classes/yf_model.class.php and 1 other location - About 1 hr to fix
              plugins/sys/classes/yf_model.class.php on lines 99..113

              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

              There are no issues that match your filters.

              Category
              Status