YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/Payments/BaseAction/ReceiveFromPaymentsSystem.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Method put has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function put()
    {
        $request = $this->controller->request;
        $paymentSystem = $request->getByType('payment_system', 'Alnum');
        if (!\App\Fields\Picklist::isExists('payment_system', $paymentSystem)) {
Severity: Minor
Found in api/webservice/Payments/BaseAction/ReceiveFromPaymentsSystem.php - About 1 hr to fix

    Missing class import via use statement (line '40', column '14').
    Open

                throw new \Api\Core\Exception('Unknown payment system');

    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 '46', column '25').
    Open

            $queryGenerator = new \App\QueryGenerator('PaymentsIn', $userId);

    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 '\Vtiger_Record_Model' in method 'put'.
    Open

            $recordModelOrder = \Vtiger_Record_Model::getInstanceById($orderId, 'SSingleOrders');

    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 '\App\Fields\Picklist' in method 'put'.
    Open

            if (!\App\Fields\Picklist::isExists('payment_system', $paymentSystem)) {

    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 '\Vtiger_Record_Model' in method 'put'.
    Open

                $recordModel = \Vtiger_Record_Model::getCleanInstance('PaymentsIn');

    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 '\Vtiger_Record_Model' in method 'put'.
    Open

                $recordModel = \Vtiger_Record_Model::getInstanceById($paymentsInId, 'PaymentsIn');

    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 put uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $recordModel = \Vtiger_Record_Model::getCleanInstance('PaymentsIn');
                $recordModel->set('assigned_user_id', $userId);
                $recordModel->set('relatedid', $recordModelOrder->get('accountid'));
                $recordModel->set('ssingleordersid', $orderId);

    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 '\App\Fields\Currency' in method 'put'.
    Open

                $recordModel->set('currency_id', \App\Fields\Currency::getIdByCode($request->getByType('currency_id')));

    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

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

            $paymentSystem = $request->getByType('payment_system', 'Alnum');

    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 "PaymentsIn" 3 times.
    Open

            $queryGenerator = new \App\QueryGenerator('PaymentsIn', $userId);

    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 "transaction_id" 3 times.
    Open

            $transactionId = $request->getByType('transaction_id', 'Alnum');

    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 "payment_system" 4 times.
    Open

            $paymentSystem = $request->getByType('payment_system', 'Alnum');

    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.

    Call to method addCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $queryGenerator->addCondition('transaction_id', $transactionId, 'e');

    Call to method addCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $queryGenerator->addCondition('payment_system', $paymentSystem, 'e');

    Call to method __construct from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $queryGenerator = new \App\QueryGenerator('PaymentsIn', $userId);

    Call to method setFields from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $queryGenerator->setFields(['paymentsinid']);

    Call to method createQuery from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

            $paymentsInId = $queryGenerator->createQuery()->scalar();

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

        protected function checkPermission(): void

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

            $queryGenerator->setFields(['paymentsinid']);

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

            $recordModel->set('paymentsin_status', $request->getByType('paymentsin_status', 'Alnum'));

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

            $recordModelOrder = \Vtiger_Record_Model::getInstanceById($orderId, 'SSingleOrders');

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

                $recordModel->set('relatedid', $recordModelOrder->get('accountid'));

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

                $recordModel->set('currency_id', \App\Fields\Currency::getIdByCode($request->getByType('currency_id')));

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

         * @return array

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

            $queryGenerator->addCondition('transaction_id', $transactionId, '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

            $userId = (int) $recordModelOrder->get('assigned_user_id');

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

                $recordModel->set('ssingleordersid', $orderId);

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

         * Handling payment information.

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

         *

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

                $recordModel->set('paymentstitle', $request->getByType('paymentstitle', 'Text'));

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

                $recordModel->set('payment_system', $paymentSystem);

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

            $transactionId = $request->getByType('transaction_id', 'Alnum');

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

        public $allowedMethod = ['PUT'];

    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

            $queryGenerator = new \App\QueryGenerator('PaymentsIn', $userId);

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

            if ($paymentsInId) {

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

         * @throws \Api\Core\Exception

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

        /** {@inheritdoc}  */

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

                throw new \Api\Core\Exception('Unknown payment system');

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

         */

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

            $paymentSystem = $request->getByType('payment_system', 'Alnum');

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

            $orderId = $request->getInteger('ssingleordersid');

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

            $queryGenerator->addCondition('payment_system', $paymentSystem, 'e');

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

            $paymentsInId = $queryGenerator->createQuery()->scalar();

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

                $recordModel->set('assigned_user_id', $userId);

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

            if (!\App\Fields\Picklist::isExists('payment_system', $paymentSystem)) {

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

            }

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

                $recordModel->set('paymentsvalue', $request->getByType('paymentsvalue', 'Double'));

    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

        /** {@inheritdoc}  */

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

        {

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

                $recordModel = \Vtiger_Record_Model::getCleanInstance('PaymentsIn');

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

                $recordModel->set('transaction_id', $transactionId);

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

            }

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

            return ['id' => $recordModel->getId()];

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

        /**

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

                $recordModel = \Vtiger_Record_Model::getInstanceById($paymentsInId, 'PaymentsIn');

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

            $recordModel->save();

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

        public function put()

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

            $request = $this->controller->request;

    There are no issues that match your filters.

    Category
    Status