src/Shop/Views/Category.php

Summary

Maintainability
B
5 hrs
Test Coverage

Method items has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function items($request, $match)
    {
        $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
        $model = Shop_Views_Category::itemModel($request, $match);
        $item = Pluf::factory($model);
Severity: Minor
Found in src/Shop/Views/Category.php - About 1 hr to fix

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

                    throw new Pluf_Exception_DoesNotExist('Unkown item model. Valid item models are: product, service and delivery. ');
    Severity: Minor
    Found in src/Shop/Views/Category.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

    Missing class import via use statement (line '55', column '21').
    Open

            $page = new Pluf_Paginator($item);
    Severity: Minor
    Found in src/Shop/Views/Category.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

    Missing class import via use statement (line '56', column '20').
    Open

            $sql = new Pluf_SQL($catIdColName . '=%s', array(
    Severity: Minor
    Found in src/Shop/Views/Category.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 using static access to class 'Shop_Views_Category' in method 'addItem'.
    Open

            $model = Shop_Views_Category::itemModel($request, $match);
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class 'Pluf' in method 'items'.
    Open

            $item = Pluf::factory($model);
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

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

            } else {
                $itemId = $request->REQUEST['id'];
            }
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

    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 using static access to class 'Shop_Views_Category' in method 'items'.
    Open

            $model = Shop_Views_Category::itemModel($request, $match);
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class 'Shop_Views_Category' in method 'removeItem'.
    Open

            $model = Shop_Views_Category::itemModel($request, $match);
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

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

            } else {
                $itemId = $request->REQUEST['id'];
            }
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

    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

    Define a constant instead of duplicating this literal "Shop_Category" 3 times.
    Open

            $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
    Severity: Critical
    Found in src/Shop/Views/Category.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "categoryId" 3 times.
    Open

            $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
    Severity: Critical
    Found in src/Shop/Views/Category.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Remove the unused function parameter "$request".
    Open

        private static function itemModel($request, $match){
    Severity: Major
    Found in src/Shop/Views/Category.php by sonar-php

    Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.

    Noncompliant Code Example

    function doSomething($a, $b) { // "$a" is unused
      return compute($b);
    }
    

    Compliant Solution

    function doSomething($b) {
      return compute($b);
    }
    

    Exceptions

    Functions in classes that override a class or implement interfaces are ignored.

    class C extends B {
    
      function doSomething($a, $b) {     // no issue reported on $b
        compute($a);
      }
    
    }
    

    See

    • MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
    • MISRA C:2012, 2.7 - There should be no unused parameters in functions
    • CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
    • CERT, MSC12-CPP. - Detect and remove code that has no effect

    Avoid unused parameters such as '$request'.
    Open

        private static function itemModel($request, $match){
    Severity: Minor
    Found in src/Shop/Views/Category.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

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

        public static function removeItem($request, $match)
        {
            $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
            if (isset($match['id'])) {
                $itemId = $match['id'];
    Severity: Major
    Found in src/Shop/Views/Category.php and 3 other locations - About 1 hr to fix
    src/Shop/Views/Category.php on lines 83..95
    src/Shop/Views/Tag.php on lines 86..98
    src/Shop/Views/Tag.php on lines 100..112

    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 4 locations. Consider refactoring.
    Open

        public static function addItem($request, $match)
        {
            $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
            if (isset($match['id'])) {
                $itemId = $match['id'];
    Severity: Major
    Found in src/Shop/Views/Category.php and 3 other locations - About 1 hr to fix
    src/Shop/Views/Category.php on lines 97..109
    src/Shop/Views/Tag.php on lines 86..98
    src/Shop/Views/Tag.php on lines 100..112

    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

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class Shop_Views_Category
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpcodesniffer

    A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 6 and the first side effect is on line 2.
    Open

    <?php
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpcodesniffer

    The class Shop_Views_Category is not named in CamelCase.
    Open

    class Shop_Views_Category
    {
        /**
         * Extracts item model from $match and retruns related Pluf_Model for item model.
         *  
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

    CamelCaseClassName

    Since: 0.2

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

    Example

    class class_name {
    }

    Source

    Line exceeds 120 characters; contains 131 characters
    Open

                    throw new Pluf_Exception_DoesNotExist('Unkown item model. Valid item models are: product, service and delivery. ');
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpcodesniffer

    Whitespace found at end of line
    Open

         *  
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpcodesniffer

    Expected 1 space after closing parenthesis; found 0
    Open

            switch ($match['item']){
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpcodesniffer

    Class name "Shop_Views_Category" is not in camel caps format
    Open

    class Shop_Views_Category
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpcodesniffer

    Opening brace should be on a new line
    Open

        private static function itemModel($request, $match){
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpcodesniffer

    Whitespace found at end of line
    Open

            $item->setView('myView', array(            
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpcodesniffer

    The variable $search_fields is not named in camelCase.
    Open

        public static function items($request, $match)
        {
            $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
            $model = Shop_Views_Category::itemModel($request, $match);
            $item = Pluf::factory($model);
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

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

        public static function items($request, $match)
        {
            $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
            $model = Shop_Views_Category::itemModel($request, $match);
            $item = Pluf::factory($model);
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

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

        public static function items($request, $match)
        {
            $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
            $model = Shop_Views_Category::itemModel($request, $match);
            $item = Pluf::factory($model);
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

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

        public static function items($request, $match)
        {
            $category = Pluf_Shortcuts_GetObjectOr404('Shop_Category', $match['categoryId']);
            $model = Shop_Views_Category::itemModel($request, $match);
            $item = Pluf::factory($model);
    Severity: Minor
    Found in src/Shop/Views/Category.php by phpmd

    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

    There are no issues that match your filters.

    Category
    Status