src/Shop/Views/Zone.php

Summary

Maintainability
A
3 hrs
Test Coverage

Method members has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function members($request, $match)
    {
        $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
        $user = new User_Account();
        $associationTable = Shop_Shortcuts_GetAssociationTableName($zone, $user);
Severity: Minor
Found in src/Shop/Views/Zone.php - About 1 hr to fix

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

            $page = new Pluf_Paginator($user);
    Severity: Minor
    Found in src/Shop/Views/Zone.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 '16', column '20').
    Open

            $sql = new Pluf_SQL('shop_zone_id=%s', array(
    Severity: Minor
    Found in src/Shop/Views/Zone.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 '9', column '21').
    Open

            $user = new User_Account();
    Severity: Minor
    Found in src/Shop/Views/Zone.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

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

            } else {
                $userId = $request->REQUEST['userId'];
            }
    Severity: Minor
    Found in src/Shop/Views/Zone.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

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

            } else {
                $userId = $request->REQUEST['userId'];
            }
    Severity: Minor
    Found in src/Shop/Views/Zone.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 "userId" 6 times.
    Open

            if (isset($match['userId'])) {
    Severity: Critical
    Found in src/Shop/Views/Zone.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 "zoneId" 3 times.
    Open

            $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
    Severity: Critical
    Found in src/Shop/Views/Zone.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 "login" 3 times.
    Open

                'login',
    Severity: Critical
    Found in src/Shop/Views/Zone.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 "Shop_Zone" 3 times.
    Open

            $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
    Severity: Critical
    Found in src/Shop/Views/Zone.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.

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

        public static function removeMember($request, $match)
        {
            $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
            if (isset($match['userId'])) {
                $userId = $match['userId'];
    Severity: Major
    Found in src/Shop/Views/Zone.php and 7 other locations - About 1 hr to fix
    src/Shop/Views/Agency.php on lines 55..66
    src/Shop/Views/Agency.php on lines 68..79
    src/Shop/Views/Tax.php on lines 50..61
    src/Shop/Views/Tax.php on lines 63..74
    src/Shop/Views/Tax.php on lines 118..129
    src/Shop/Views/Tax.php on lines 131..142
    src/Shop/Views/Zone.php on lines 52..63

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

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

        public static function addMember($request, $match)
        {
            $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
            if (isset($match['userId'])) {
                $userId = $match['userId'];
    Severity: Major
    Found in src/Shop/Views/Zone.php and 7 other locations - About 1 hr to fix
    src/Shop/Views/Agency.php on lines 55..66
    src/Shop/Views/Agency.php on lines 68..79
    src/Shop/Views/Tax.php on lines 50..61
    src/Shop/Views/Tax.php on lines 63..74
    src/Shop/Views/Tax.php on lines 118..129
    src/Shop/Views/Tax.php on lines 131..142
    src/Shop/Views/Zone.php on lines 65..76

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

    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_Zone
    Severity: Minor
    Found in src/Shop/Views/Zone.php by phpcodesniffer

    The class Shop_Views_Zone is not named in CamelCase.
    Open

    class Shop_Views_Zone
    {
    
        public static function members($request, $match)
        {
    Severity: Minor
    Found in src/Shop/Views/Zone.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

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

    class Shop_Views_Zone
    Severity: Minor
    Found in src/Shop/Views/Zone.php by phpcodesniffer

    Expected 1 newline at end of file; 0 found
    Open

    }
    Severity: Minor
    Found in src/Shop/Views/Zone.php by phpcodesniffer

    The variable $sort_fields is not named in camelCase.
    Open

        public static function members($request, $match)
        {
            $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
            $user = new User_Account();
            $associationTable = Shop_Shortcuts_GetAssociationTableName($zone, $user);
    Severity: Minor
    Found in src/Shop/Views/Zone.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 members($request, $match)
        {
            $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
            $user = new User_Account();
            $associationTable = Shop_Shortcuts_GetAssociationTableName($zone, $user);
    Severity: Minor
    Found in src/Shop/Views/Zone.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 members($request, $match)
        {
            $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
            $user = new User_Account();
            $associationTable = Shop_Shortcuts_GetAssociationTableName($zone, $user);
    Severity: Minor
    Found in src/Shop/Views/Zone.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 members($request, $match)
        {
            $zone = Pluf_Shortcuts_GetObjectOr404('Shop_Zone', $match['zoneId']);
            $user = new User_Account();
            $associationTable = Shop_Shortcuts_GetAssociationTableName($zone, $user);
    Severity: Minor
    Found in src/Shop/Views/Zone.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