src/Shop/Agency.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method init has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    function init()
    {
        parent::init();
        $this->_a['table'] = 'shop_agency';
        $this->_a['model'] = 'Shop_Agency';
Severity: Major
Found in src/Shop/Agency.php - About 2 hrs to fix

    The method preSave has a boolean flag argument $create, which is a certain sign of a Single Responsibility Principle violation.
    Open

        function preSave($create = false)
    Severity: Minor
    Found in src/Shop/Agency.php by phpmd

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

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

    Define a constant instead of duplicating this literal "editable" 9 times.
    Open

                    'editable' => true,
    Severity: Critical
    Found in src/Shop/Agency.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

            foreach ($usres as $u)
    Severity: Critical
    Found in src/Shop/Agency.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 "Varchar" 4 times.
    Open

                    'type' => 'Varchar',
    Severity: Critical
    Found in src/Shop/Agency.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 "readable" 6 times.
    Open

                    'readable' => true
    Severity: Critical
    Found in src/Shop/Agency.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 "is_null" 8 times.
    Open

                    'is_null' => true,
    Severity: Critical
    Found in src/Shop/Agency.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 ($u->getId() == $user->getId())
    Severity: Critical
    Found in src/Shop/Agency.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

    Avoid unused parameters such as '$create'.
    Open

        function preSave($create = false)
    Severity: Minor
    Found in src/Shop/Agency.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

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

    class Shop_Agency extends Shop_DetailedObject
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    The class Shop_Agency is not named in CamelCase.
    Open

    class Shop_Agency extends Shop_DetailedObject
    {
    
        /**
         *
    Severity: Minor
    Found in src/Shop/Agency.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

    Visibility must be declared on method "isOwner"
    Open

        function isOwner($user)
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    Visibility must be declared on method "preSave"
    Open

        function preSave($create = false)
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    Visibility must be declared on method "init"
    Open

        function init()
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    Line exceeds 120 characters; contains 159 characters
    Open

         * در این فرآیند نیازهای ابتدایی سیستم به آن اضافه می‌شود. این نیازها مقادیری هستند که
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    Inline control structures are not allowed
    Open

                if ($u->getId() == $user->getId())
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    Line exceeds 120 characters; contains 147 characters
    Open

         * در زمان ایجاد باید تعیین شوند. از این جمله می‌توان به کاربر و تاریخ اشاره کرد.
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    Line exceeds 120 characters; contains 132 characters
    Open

         * تمام فیلدهای مورد نیاز برای این مدل داده‌ای در این متد تعیین شده و به
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    Inline control structures are not allowed
    Open

            foreach ($usres as $u)
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

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

    class Shop_Agency extends Shop_DetailedObject
    Severity: Minor
    Found in src/Shop/Agency.php by phpcodesniffer

    Whitespace found at end of line
    Open

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

    Expected 1 newline at end of file; 0 found
    Open

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

    There are no issues that match your filters.

    Category
    Status