steadlane/silverstripe-searchify

View on GitHub
code/Searchify.php

Summary

Maintainability
D
1 day
Test Coverage

File Searchify.php has 329 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

class Searchify extends Object
{

Severity: Minor
Found in code/Searchify.php - About 3 hrs to fix

    The class Searchify has an overall complexity of 58 which is very high. The configured complexity threshold is 50.
    Open

    class Searchify extends Object
    {
    
        /**
         * @var Indextank_Api
    Severity: Minor
    Found in code/Searchify.php by phpmd

    Method addPage has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function addPage($record)
        {
            if (!$this->index instanceof \Indextank_Index) {
                user_error(
                    _t(
    Severity: Minor
    Found in code/Searchify.php - About 1 hr to fix

      Method addPages has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function addPages($records)
          {
              if (!$records->count()) {
                  return false;
              }
      Severity: Minor
      Found in code/Searchify.php - About 1 hr to fix

        Method discover has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function discover($record)
            {
                $config = \Config::inst()->get($record->ClassName, 'db');
        
                $content = array(
        Severity: Minor
        Found in code/Searchify.php - About 1 hr to fix

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

              public function removePage($record)
              {
                  if (!$this->index instanceof \Indextank_Index) {
                      user_error(
                          _t(
          Severity: Minor
          Found in code/Searchify.php - About 1 hr to fix

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

                public function setIndex($key)
                {
                    $indexes = $this->getIndexList();
                    if (!isset($indexes[$key])) {
                        if (!$this->config()->make_index) {
            Severity: Minor
            Found in code/Searchify.php - About 1 hr to fix

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

                  public function discover($record)
                  {
                      $config = \Config::inst()->get($record->ClassName, 'db');
              
                      $content = array(
              Severity: Minor
              Found in code/Searchify.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

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

                  public function addPages($records)
                  {
                      if (!$records->count()) {
                          return false;
                      }
              Severity: Minor
              Found in code/Searchify.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

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

                  public function indexAll()
                  {
                      $pages = SiteTree::get();
              
                      if (!$pages) {
              Severity: Minor
              Found in code/Searchify.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

              Missing class import via use statement (line '32', column '29').
              Open

                      $this->client = new Indextank_Api($apiUrl);
              Severity: Minor
              Found in code/Searchify.php by phpmd

              MissingImport

              Since: 2.7.0

              Importing all external classes in a file through use statements makes them clearly visible.

              Example

              function make() {
                  return new \stdClass();
              }

              Source http://phpmd.org/rules/cleancode.html#MissingImport

              Avoid unused parameters such as '$records'.
              Open

                  public function removePages(ArrayList $records)
              Severity: Minor
              Found in code/Searchify.php by phpmd

              UnusedFormalParameter

              Since: 0.2

              Avoid passing parameters to methods or constructors and then not using those parameters.

              Example

              class Foo
              {
                  private function bar($howdy)
                  {
                      // $howdy is not used
                  }
              }

              Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

              There are no issues that match your filters.

              Category
              Status