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)) {
Missing class import via use statement (line '40', column '14'). Open
throw new \Api\Core\Exception('Unknown payment system');
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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')));
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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');
- Exclude checks
Call to method addCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->addCondition('payment_system', $paymentSystem, 'e');
- Exclude checks
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = new \App\QueryGenerator('PaymentsIn', $userId);
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setFields(['paymentsinid']);
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$paymentsInId = $queryGenerator->createQuery()->scalar();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected function checkPermission(): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setFields(['paymentsinid']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('paymentsin_status', $request->getByType('paymentsin_status', 'Alnum'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModelOrder = \Vtiger_Record_Model::getInstanceById($orderId, 'SSingleOrders');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('relatedid', $recordModelOrder->get('accountid'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('currency_id', \App\Fields\Currency::getIdByCode($request->getByType('currency_id')));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->addCondition('transaction_id', $transactionId, 'e');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userId = (int) $recordModelOrder->get('assigned_user_id');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('ssingleordersid', $orderId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Handling payment information.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('paymentstitle', $request->getByType('paymentstitle', 'Text'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('payment_system', $paymentSystem);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$transactionId = $request->getByType('transaction_id', 'Alnum');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $allowedMethod = ['PUT'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = new \App\QueryGenerator('PaymentsIn', $userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($paymentsInId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \Api\Core\Exception
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \Api\Core\Exception('Unknown payment system');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$paymentSystem = $request->getByType('payment_system', 'Alnum');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$orderId = $request->getInteger('ssingleordersid');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->addCondition('payment_system', $paymentSystem, 'e');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$paymentsInId = $queryGenerator->createQuery()->scalar();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('assigned_user_id', $userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\App\Fields\Picklist::isExists('payment_system', $paymentSystem)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('paymentsvalue', $request->getByType('paymentsvalue', 'Double'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = \Vtiger_Record_Model::getCleanInstance('PaymentsIn');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('transaction_id', $transactionId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ['id' => $recordModel->getId()];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = \Vtiger_Record_Model::getInstanceById($paymentsInId, 'PaymentsIn');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function put()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$request = $this->controller->request;
- Exclude checks