src/Shop/Views/Contact.php

Summary

Maintainability
A
1 hr
Test Coverage

Method find has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function find($request, $match)
    {
        $contact = new Shop_Contact();
        $pag = new Pluf_Paginator($contact);
        if (User_Precondition::ownerRequired($request)) {
Severity: Minor
Found in src/Shop/Views/Contact.php - About 1 hr to fix

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

            $pag = new Pluf_Paginator($contact);
    Severity: Minor
    Found in src/Shop/Views/Contact.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 '89', column '19').
    Open

            throw new Pluf_Exception_PermissionDenied("Permission is denied");
    Severity: Minor
    Found in src/Shop/Views/Contact.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 '61', column '19').
    Open

            throw new Pluf_Exception_PermissionDenied("Permission is denied");
    Severity: Minor
    Found in src/Shop/Views/Contact.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 '13', column '38').
    Open

                $pag->forced_where = new Pluf_SQL();
    Severity: Minor
    Found in src/Shop/Views/Contact.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 '79', column '19').
    Open

            throw new Pluf_Exception_PermissionDenied("Permission is denied");
    Severity: Minor
    Found in src/Shop/Views/Contact.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 '10', column '24').
    Open

            $contact = new Shop_Contact();
    Severity: Minor
    Found in src/Shop/Views/Contact.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 '15', column '38').
    Open

                $pag->forced_where = new Pluf_SQL('user=' . $request->user->id);
    Severity: Minor
    Found in src/Shop/Views/Contact.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 'User_Precondition' in method 'canAccess'.
    Open

            return ($user != null && $currentUser_Account->getId() === $user->getId()) || User_Precondition::ownerRequired($request);
    Severity: Minor
    Found in src/Shop/Views/Contact.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 'User_Precondition' in method 'find'.
    Open

            if (User_Precondition::ownerRequired($request)) {
    Severity: Minor
    Found in src/Shop/Views/Contact.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 find uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $pag->forced_where = new Pluf_SQL('user=' . $request->user->id);
            }
    Severity: Minor
    Found in src/Shop/Views/Contact.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 'Pluf' in method 'create'.
    Open

            $form = Pluf_Shortcuts_GetFormForModel(Pluf::factory('Shop_Contact'), $request->REQUEST);
    Severity: Minor
    Found in src/Shop/Views/Contact.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

    Remove the unused function parameter "$match".
    Open

        public static function create($request, $match)
    Severity: Major
    Found in src/Shop/Views/Contact.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

    Define a constant instead of duplicating this literal "Permission is denied" 3 times.
    Open

            throw new Pluf_Exception_PermissionDenied("Permission is denied");
    Severity: Critical
    Found in src/Shop/Views/Contact.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 "$match".
    Open

        public static function find($request, $match)
    Severity: Major
    Found in src/Shop/Views/Contact.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

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

                'contact',
    Severity: Critical
    Found in src/Shop/Views/Contact.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.

    Add curly braces around the nested statement(s).
    Open

            if (self::canAccess($request, $contact))
    Severity: Critical
    Found in src/Shop/Views/Contact.php by sonar-php

    While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.

    Noncompliant Code Example

    if (condition)  // Noncompliant
      executeSomething();
    

    Compliant Solution

    if (condition) {
      executeSomething();
    }
    

    See

    • MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
    • MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
    • MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
    • MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
    • MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
    • CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
    • CERT, EXP52-J. - Use braces for the body of an if, for, or while statement

    Define a constant instead of duplicating this literal "Shop_Contact" 4 times.
    Open

            $form = Pluf_Shortcuts_GetFormForModel(Pluf::factory('Shop_Contact'), $request->REQUEST);
    Severity: Critical
    Found in src/Shop/Views/Contact.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 "contactId" 3 times.
    Open

            $contact = Pluf_Shortcuts_GetObjectOr404('Shop_Contact', $match['contactId']);
    Severity: Critical
    Found in src/Shop/Views/Contact.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.

    Avoid unused parameters such as '$match'.
    Open

        public static function find($request, $match)
    Severity: Minor
    Found in src/Shop/Views/Contact.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

    Avoid unused parameters such as '$match'.
    Open

        public static function create($request, $match)
    Severity: Minor
    Found in src/Shop/Views/Contact.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 2 locations. Consider refactoring.
    Open

        public static function update($request, $match)
        {
            $contact = Pluf_Shortcuts_GetObjectOr404('Shop_Contact', $match['contactId']);
            if (self::canAccess($request, $contact)) {
                $form = Pluf_Shortcuts_GetFormForUpdateModel($contact, $request->REQUEST);
    Severity: Minor
    Found in src/Shop/Views/Contact.php and 1 other location - About 30 mins to fix
    src/Shop/Views/Address.php on lines 78..87

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

    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_Contact
    Severity: Minor
    Found in src/Shop/Views/Contact.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 5 and the first side effect is on line 2.
    Open

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

    The class Shop_Views_Contact is not named in CamelCase.
    Open

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

    Inline control structures are not allowed
    Open

            if (self::canAccess($request, $contact))
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

    Line exceeds 120 characters; contains 129 characters
    Open

            return ($user != null && $currentUser_Account->getId() === $user->getId()) || User_Precondition::ownerRequired($request);
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

    Whitespace found at end of line
    Open

         * @param array $match            
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

    Whitespace found at end of line
    Open

         * @param Shop_Contact $contact            
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

    Whitespace found at end of line
    Open

         * @param array $match            
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

    Whitespace found at end of line
    Open

         * @param Pluf_HTTP_Request $request            
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

    Expected 1 newline at end of file; 0 found
    Open

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

    Whitespace found at end of line
    Open

         * @param Pluf_HTTP_Request $request            
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

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

    class Shop_Views_Contact
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

    Whitespace found at end of line
    Open

         * @param Pluf_HTTP_Request $request            
    Severity: Minor
    Found in src/Shop/Views/Contact.php by phpcodesniffer

    The variable $sort_fields is not named in camelCase.
    Open

        public static function find($request, $match)
        {
            $contact = new Shop_Contact();
            $pag = new Pluf_Paginator($contact);
            if (User_Precondition::ownerRequired($request)) {
    Severity: Minor
    Found in src/Shop/Views/Contact.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 find($request, $match)
        {
            $contact = new Shop_Contact();
            $pag = new Pluf_Paginator($contact);
            if (User_Precondition::ownerRequired($request)) {
    Severity: Minor
    Found in src/Shop/Views/Contact.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 find($request, $match)
        {
            $contact = new Shop_Contact();
            $pag = new Pluf_Paginator($contact);
            if (User_Precondition::ownerRequired($request)) {
    Severity: Minor
    Found in src/Shop/Views/Contact.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 $currentUser_Account is not named in camelCase.
    Open

        private static function canAccess($request, $contact)
        {
            $currentUser_Account = $request->user;
            $user = $contact->get_user();
            return ($user != null && $currentUser_Account->getId() === $user->getId()) || User_Precondition::ownerRequired($request);
    Severity: Minor
    Found in src/Shop/Views/Contact.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 find($request, $match)
        {
            $contact = new Shop_Contact();
            $pag = new Pluf_Paginator($contact);
            if (User_Precondition::ownerRequired($request)) {
    Severity: Minor
    Found in src/Shop/Views/Contact.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 $currentUser_Account is not named in camelCase.
    Open

        private static function canAccess($request, $contact)
        {
            $currentUser_Account = $request->user;
            $user = $contact->get_user();
            return ($user != null && $currentUser_Account->getId() === $user->getId()) || User_Precondition::ownerRequired($request);
    Severity: Minor
    Found in src/Shop/Views/Contact.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