amtgard/ORK3

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

Summary

Maintainability
F
3 days
Test Coverage

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

<?php

class SearchService extends Ork3 {

    public function __construct() {
Severity: Minor
Found in system/lib/ork3/class.SearchService.php - About 3 hrs to fix

    Function Player has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        public function Player($type, $search, $limit=15, $kingdom_id = null, $park_id = null, $waivered = null, $persona_required = true) {
            list($search, $kingdom_id, $park_id) = $this->magic_search($search, $kingdom_id, $park_id);
                    
            $searchtokens = preg_split("/[\s,-]+/", $search ?? '');
            $opt = array("1");
    Severity: Minor
    Found in system/lib/ork3/class.SearchService.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

    Function Event has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        public function Event($name = null, $kingdom_id = null, $park_id = null, $mundane_id = null, $unit_id = null, $limit = 10, $event_id = null, $date_order = null, $date_start = null, $current = 1) {
            $keys = func_get_args();
            if (count($keys) > 0)
                $keys[0] = substr($keys[0] ?? '', 0, 4);
            $key = Ork3::$Lib->ghettocache->key($keys); 
    Severity: Minor
    Found in system/lib/ork3/class.SearchService.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

    Method Player has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function Player($type, $search, $limit=15, $kingdom_id = null, $park_id = null, $waivered = null, $persona_required = true) {
            list($search, $kingdom_id, $park_id) = $this->magic_search($search, $kingdom_id, $park_id);
                    
            $searchtokens = preg_split("/[\s,-]+/", $search ?? '');
            $opt = array("1");
    Severity: Major
    Found in system/lib/ork3/class.SearchService.php - About 3 hrs to fix

      Method Location has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function Location($name, $date) {
              $key = Ork3::$Lib->ghettocache->key(array(substr($name, 0, 3), $date)); 
              if (strlen($name) <= 3 && ($cache = Ork3::$Lib->ghettocache->get(__CLASS__ . '.' . __FUNCTION__, $key, 30)) !== false)
                  return $cache;
              
      Severity: Major
      Found in system/lib/ork3/class.SearchService.php - About 2 hrs to fix

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

            public function Event($name = null, $kingdom_id = null, $park_id = null, $mundane_id = null, $unit_id = null, $limit = 10, $event_id = null, $date_order = null, $date_start = null, $current = 1) {
                $keys = func_get_args();
                if (count($keys) > 0)
                    $keys[0] = substr($keys[0] ?? '', 0, 4);
                $key = Ork3::$Lib->ghettocache->key($keys); 
        Severity: Major
        Found in system/lib/ork3/class.SearchService.php - About 2 hrs to fix

          Method Event has 10 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function Event($name = null, $kingdom_id = null, $park_id = null, $mundane_id = null, $unit_id = null, $limit = 10, $event_id = null, $date_order = null, $date_start = null, $current = 1) {
          Severity: Major
          Found in system/lib/ork3/class.SearchService.php - About 1 hr to fix

            Function Park has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                public function Park($name, $kingdom_id = null, $limit = null) {
                    
                    $key = Ork3::$Lib->ghettocache->key(array(substr($name, 0, 2), $kingdom_id, $limit)); 
                    if (strlen($name) == 2 && ($cache = Ork3::$Lib->ghettocache->get(__CLASS__ . '.' . __FUNCTION__, $key, 600)) !== false)
                        return $cache;
            Severity: Minor
            Found in system/lib/ork3/class.SearchService.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 CalendarDetail has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function CalendarDetail($event_calendardetail_id) {
                    $key = Ork3::$Lib->ghettocache->key(func_get_args()); 
                    if (($cache = Ork3::$Lib->ghettocache->get(__CLASS__ . '.' . __FUNCTION__, $key, 30)) !== false)
                        return $cache;
                    
            Severity: Minor
            Found in system/lib/ork3/class.SearchService.php - About 1 hr to fix

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

                  public function Park($name, $kingdom_id = null, $limit = null) {
                      
                      $key = Ork3::$Lib->ghettocache->key(array(substr($name, 0, 2), $kingdom_id, $limit)); 
                      if (strlen($name) == 2 && ($cache = Ork3::$Lib->ghettocache->get(__CLASS__ . '.' . __FUNCTION__, $key, 600)) !== false)
                          return $cache;
              Severity: Minor
              Found in system/lib/ork3/class.SearchService.php - About 1 hr to fix

                Function Kingdom has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function Kingdom($name, $limit = null) {
                        
                        $key = Ork3::$Lib->ghettocache->key(array(substr($name, 0, 3), $kingdom_id, $limit)); 
                        if (($cache = Ork3::$Lib->ghettocache->get(__CLASS__ . '.' . __FUNCTION__, $key, 600)) !== false)
                            return $cache;
                Severity: Minor
                Found in system/lib/ork3/class.SearchService.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 Player has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public function Player($type, $search, $limit=15, $kingdom_id = null, $park_id = null, $waivered = null, $persona_required = true) {
                Severity: Major
                Found in system/lib/ork3/class.SearchService.php - About 50 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return array();
                  Severity: Major
                  Found in system/lib/ork3/class.SearchService.php - About 30 mins to fix

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

                        public function Location($name, $date) {
                            $key = Ork3::$Lib->ghettocache->key(array(substr($name, 0, 3), $date)); 
                            if (strlen($name) <= 3 && ($cache = Ork3::$Lib->ghettocache->get(__CLASS__ . '.' . __FUNCTION__, $key, 30)) !== false)
                                return $cache;
                            
                    Severity: Minor
                    Found in system/lib/ork3/class.SearchService.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

                                case 'USER':
                                    if (count($searchtokens) > 0)
                                        $s = implode(' or ', array_map(function($t) { return "`username` like '%" . mysql_real_escape_string($t) . "%'"; }, $searchtokens));
                                        $order = "order by username,surname,given_name";
                                        $opt[] = "length(`username`) > 0";
                    Severity: Minor
                    Found in system/lib/ork3/class.SearchService.php and 1 other location - About 30 mins to fix
                    system/lib/ork3/class.SearchService.php on lines 272..277

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

                    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

                                case 'PERSONA': 
                                    if (count($searchtokens) > 0)
                                        $s = implode(' or ', array_map(function($t) { return "`persona` like '%" . mysql_real_escape_string($t) . "%'"; }, $searchtokens));
                                        $order = "order by persona,surname,given_name";
                                        $opt[] = "length(`persona`) > 0";
                    Severity: Minor
                    Found in system/lib/ork3/class.SearchService.php and 1 other location - About 30 mins to fix
                    system/lib/ork3/class.SearchService.php on lines 284..289

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

                    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