YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/YetiForce/actions/Buy.php

Summary

Maintainability
B
4 hrs
Test Coverage

Method process has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        try {
            $orderId = $message = '';
            $responseType = 'success';
Severity: Minor
Found in modules/Settings/YetiForce/actions/Buy.php - About 1 hr to fix

    Function process has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        public function process(App\Request $request)
        {
            try {
                $orderId = $message = '';
                $responseType = 'success';
    Severity: Minor
    Found in modules/Settings/YetiForce/actions/Buy.php - About 1 hr 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

    The method process() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
    Open

        public function process(App\Request $request)
        {
            try {
                $orderId = $message = '';
                $responseType = 'success';

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Missing class import via use statement (line '63', column '19').
    Open

            $response = new Vtiger_Response();

    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 '43', column '16').
    Open

                        throw new \App\Exceptions\AppException('LBL_NOT_FILLED_MANDATORY_FIELDS');

    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 '37', column '17').
    Open

                            throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');

    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 '30', column '17').
    Open

                $order = new \App\YetiForce\Order();

    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 '48', column '15').
    Open

                    throw new \App\Exceptions\AppException($error);

    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 assigning values to variables in if clauses and the like (line '47', column '8').
    Open

        public function process(App\Request $request)
        {
            try {
                $orderId = $message = '';
                $responseType = 'success';

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

                    } else {
                        throw new \App\Exceptions\AppException('LBL_NOT_FILLED_MANDATORY_FIELDS');
                    }

    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 unused local variables such as '$mas'.
    Open

                        if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    Call to method send from undeclared class \App\YetiForce\Order
    Open

                $result = $order->send();
    Severity: Critical
    Found in modules/Settings/YetiForce/actions/Buy.php by phan

    Call to method getId from undeclared class \App\YetiForce\Order
    Open

                    $orderId = $order->getId();
    Severity: Critical
    Found in modules/Settings/YetiForce/actions/Buy.php by phan

    Call to method getError from undeclared class \App\YetiForce\Order
    Open

                if ($error = $order->getError()) {
    Severity: Critical
    Found in modules/Settings/YetiForce/actions/Buy.php by phan

    Call to method set from undeclared class \App\YetiForce\Order
    Open

                        $order->set($fieldName, $field->getDBValue($value));
    Severity: Critical
    Found in modules/Settings/YetiForce/actions/Buy.php by phan

    Call to method setPackageId from undeclared class \App\YetiForce\Order
    Open

                $order->setPackageId($request->getByType('packageId', \App\Purifier::ALNUM2));
    Severity: Critical
    Found in modules/Settings/YetiForce/actions/Buy.php by phan

    Call to method getFieldInstances from undeclared class \App\YetiForce\Order
    Open

                foreach ($order->getFieldInstances() as $field) {
    Severity: Critical
    Found in modules/Settings/YetiForce/actions/Buy.php by phan

    Call to method __construct from undeclared class \App\YetiForce\Order
    Open

                $order = new \App\YetiForce\Order();
    Severity: Critical
    Found in modules/Settings/YetiForce/actions/Buy.php by phan

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

                    if ($request->has($fieldName) && !$request->isEmpty($fieldName)) {
                        $value = $request->getRaw($fieldName);
                        if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {
                            throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');
                        }
    Severity: Major
    Found in modules/Settings/YetiForce/actions/Buy.php and 1 other location - About 1 hr to fix
    modules/Settings/Companies/actions/SaveAjax.php on lines 29..38

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

    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 Settings_YetiForce_Buy_Action extends Settings_Vtiger_Save_Action

    The class Settings_YetiForce_Buy_Action is not named in CamelCase.
    Open

    class Settings_YetiForce_Buy_Action extends Settings_Vtiger_Save_Action
    {
        /**
         * Process user request.
         *

    CamelCaseClassName

    Since: 0.2

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

    Example

    class class_name {
    }

    Source

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $value = $request->getRaw($fieldName);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $order->set($fieldName, $field->getDBValue($value));

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $responseType = 'error';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    if ($request->has($fieldName) && !$request->isEmpty($fieldName)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $result = $order->send();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $order->setPackageId($request->getByType('packageId', \App\Purifier::ALNUM2));

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Process user request.

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $order = new \App\YetiForce\Order();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                foreach ($order->getFieldInstances() as $field) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $field->getUITypeModel()->validate($value, true);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param \App\Request $request

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $fieldName = $field->getName();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $responseType = 'error';

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $value = $request->getByType($fieldName, $field->get('purifyType'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $result = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        throw new \App\Exceptions\AppException('LBL_NOT_FILLED_MANDATORY_FIELDS');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if ($error = $order->getError()) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $message = $e->getDisplayMessage();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $message = $e->getMessage();

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $response = new Vtiger_Response();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $responseType = 'success';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    throw new \App\Exceptions\AppException($error);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $response->setResult([

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'message' => $message ?? '',

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if ($result) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $orderId = $order->getId();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'orderId' => $orderId

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $response->emit();

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @throws \App\Exceptions\NoPermitted

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function process(App\Request $request)

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } catch (\Throwable $e) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } catch (\App\Exceptions\AppException $e) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $result = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            try {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $orderId = $message = '';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'type' => $responseType,

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'success' => $result ?? false,

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ]);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

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

    class Settings_YetiForce_Buy_Action extends Settings_Vtiger_Save_Action

    There are no issues that match your filters.

    Category
    Status