steadlane/silverstripe-searchify

View on GitHub
code/pages/SearchifyPageController.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

    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

    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

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

            } else {
                $results = false;
            }

    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

    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

    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 variable $snippet_summary is not named in camelCase.
    Open

        public function index(SS_HTTPRequest $r)
        {
            $results = Searchify::inst()->search($r->requestVar('q'));
            $resultStack = array();
    
    

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $snippet_text is not named in camelCase.
    Open

        public function index(SS_HTTPRequest $r)
        {
            $results = Searchify::inst()->search($r->requestVar('q'));
            $resultStack = array();
    
    

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $snippet_summary is not named in camelCase.
    Open

        public function index(SS_HTTPRequest $r)
        {
            $results = Searchify::inst()->search($r->requestVar('q'));
            $resultStack = array();
    
    

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $snippet_text is not named in camelCase.
    Open

        public function index(SS_HTTPRequest $r)
        {
            $results = Searchify::inst()->search($r->requestVar('q'));
            $resultStack = array();
    
    

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $snippet_text is not named in camelCase.
    Open

        public function index(SS_HTTPRequest $r)
        {
            $results = Searchify::inst()->search($r->requestVar('q'));
            $resultStack = array();
    
    

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $snippet_summary is not named in camelCase.
    Open

        public function index(SS_HTTPRequest $r)
        {
            $results = Searchify::inst()->search($r->requestVar('q'));
            $resultStack = array();
    
    

    CamelCaseVariableName

    Since: 0.2

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

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The method SearchForm is not named in camelCase.
    Open

        public function SearchForm()
        {
            return SearchForm::create(
                $this,
                "SearchForm",

    CamelCaseMethodName

    Since: 0.2

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

    Example

    class ClassName {
        public function get_name() {
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status