steadlane/silverstripe-searchify

View on GitHub

Showing 31 of 31 total issues

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 index has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function index(SS_HTTPRequest $r)
          {
              $results = Searchify::inst()->search($r->requestVar('q'));
              $resultStack = array();
      
      
      Severity: Minor
      Found in code/pages/SearchifyPageController.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

                The property $allowed_actions is not named in camelCase.
                Open

                class SearchifyPage_ControllerExtension extends Extension
                {
                    private static $allowed_actions = array(
                        'SearchForm',
                    );

                CamelCasePropertyName

                Since: 0.2

                It is considered best practice to use the camelCase notation to name attributes.

                Example

                class ClassName {
                    protected $property_name;
                }

                Source

                The class SearchifyPage_Controller is not named in CamelCase.
                Open

                class SearchifyPage_Controller extends Page_Controller
                {
                    private static $allowed_actions = array(
                        'index'
                    );

                CamelCaseClassName

                Since: 0.2

                It is considered best practice to use the CamelCase notation to name classes.

                Example

                class class_name {
                }

                Source

                The class SearchifyPage_ControllerExtension is not named in CamelCase.
                Open

                class SearchifyPage_ControllerExtension extends Extension
                {
                    private static $allowed_actions = array(
                        'SearchForm',
                    );

                CamelCaseClassName

                Since: 0.2

                It is considered best practice to use the CamelCase notation to name classes.

                Example

                class class_name {
                }

                Source

                The property $allowed_actions is not named in camelCase.
                Open

                class SearchifyPage_Controller extends Page_Controller
                {
                    private static $allowed_actions = array(
                        'index'
                    );

                CamelCasePropertyName

                Since: 0.2

                It is considered best practice to use the camelCase notation to name attributes.

                Example

                class ClassName {
                    protected $property_name;
                }

                Source

                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

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

                    public function index(SS_HTTPRequest $r)
                    {
                        $results = Searchify::inst()->search($r->requestVar('q'));
                        $resultStack = array();
                
                
                Severity: Minor
                Found in code/pages/SearchifyPageController.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

                The method onAfterPublish uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                Open

                        } else {
                            Searchify::inst()->removePage($record);
                        }

                ElseExpression

                Since: 1.4.0

                An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                Example

                class Foo
                {
                    public function bar($flag)
                    {
                        if ($flag) {
                            // one branch
                        } else {
                            // another branch
                        }
                    }
                }

                Source https://phpmd.org/rules/cleancode.html#elseexpression

                Avoid unused private fields such as '$allowed_actions'.
                Open

                    private static $allowed_actions = array(
                        'index'
                    );

                UnusedPrivateField

                Since: 0.2

                Detects when a private field is declared and/or assigned a value, but not used.

                Example

                class Something
                {
                    private static $FOO = 2; // Unused
                    private $i = 5; // Unused
                    private $j = 6;
                    public function addOne()
                    {
                        return $this->j++;
                    }
                }

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

                Avoid unused private fields such as '$allowed_actions'.
                Open

                    private static $allowed_actions = array(
                        'SearchForm',
                    );

                UnusedPrivateField

                Since: 0.2

                Detects when a private field is declared and/or assigned a value, but not used.

                Example

                class Something
                {
                    private static $FOO = 2; // Unused
                    private $i = 5; // Unused
                    private $j = 6;
                    public function addOne()
                    {
                        return $this->j++;
                    }
                }

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

                Severity
                Category
                Status
                Source
                Language