YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/WebserviceStandard/Save.php

Summary

Maintainability
A
1 hr
Test Coverage
A
100%

Function getRecordModelFromRequest has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getRecordModelFromRequest(\App\Request $request)
    {
        $fieldModelList = $this->record->getModule()->getFields();
        $requestKeys = $request->getAllRaw();
        unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);
Severity: Minor
Found in api/webservice/WebserviceStandard/Save.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

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

            throw new \Api\Core\Exception('No input data', 406);

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 '\Api\Core\Module' in method 'getRecordModelFromRequest'.
Open

        $fieldInfo = \Api\Core\Module::getApiFieldPermission($request->getModule(), $this->appId);

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

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

        $requestKeys = $request->getAllRaw();

Spaces must be used for alignment; tabs are not allowed
Open

        if ($request->has('inventory') && $this->record->getModule()->isInventory()) {

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

    protected $appId;

Spaces must be used for alignment; tabs are not allowed
Open

     * Constructor removed.

Spaces must be used for alignment; tabs are not allowed
Open

            if ($request->has($fieldName)) {

Spaces must be used for alignment; tabs are not allowed
Open

                unset($requestKeys[$fieldName]);

Spaces must be used for alignment; tabs are not allowed
Open

    public $skippedData = [];

Spaces must be used for alignment; tabs are not allowed
Open

     * @return void

Spaces must be used for alignment; tabs are not allowed
Open

            throw new \Api\Core\Exception('No input data', 406);

Spaces must be used for alignment; tabs are not allowed
Open

        foreach ($fieldModelList as $fieldName => $fieldModel) {

Spaces must be used for alignment; tabs are not allowed
Open

    /** @var int ID of application. */

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

    public function __construct()

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

        $fieldModelList = $this->record->getModule()->getFields();

Spaces must be used for alignment; tabs are not allowed
Open

            }

Spaces must be used for alignment; tabs are not allowed
Open

        $fieldInfo = \Api\Core\Module::getApiFieldPermission($request->getModule(), $this->appId);

Spaces must be used for alignment; tabs are not allowed
Open

        $this->record = $record->recordModel;

Spaces must be used for alignment; tabs are not allowed
Open

            unset($requestKeys['inventory']);

Spaces must be used for alignment; tabs are not allowed
Open

    /** @var array Skipped value. */

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

            if (!$fieldModel->isWritable()) {

Spaces must be used for alignment; tabs are not allowed
Open

    {

Spaces must be used for alignment; tabs are not allowed
Open

    protected function getRecordModelFromRequest(\App\Request $request)

Spaces must be used for alignment; tabs are not allowed
Open

                $fieldModel->getUITypeModel()->setValueFromRequest($request, $this->record);

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

                continue;

Spaces must be used for alignment; tabs are not allowed
Open

        return $this->record;

Spaces must be used for alignment; tabs are not allowed
Open

    /**

Spaces must be used for alignment; tabs are not allowed
Open

    }

Spaces must be used for alignment; tabs are not allowed
Open

        if (empty($requestKeys)) {

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

            $this->record->initInventoryDataFromRequest($request);

Spaces must be used for alignment; tabs are not allowed
Open

     * Initialization with API data.

Spaces must be used for alignment; tabs are not allowed
Open

     * @param BaseModule\Record|Users\Record $record

Spaces must be used for alignment; tabs are not allowed
Open

    public function init(\Api\Core\BaseAction $record): void

Spaces must be used for alignment; tabs are not allowed
Open

    /** {@inheritdoc}  */

Spaces must be used for alignment; tabs are not allowed
Open

 * @author    Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>

Spaces must be used for alignment; tabs are not allowed
Open

     */

Spaces must be used for alignment; tabs are not allowed
Open

        $this->appId = $record->controller->app['id'];

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

        }

Spaces must be used for alignment; tabs are not allowed
Open

            $this->record->setDataForSave([$fieldInfo['tablename'] => [$fieldInfo['columnname'] => 1]]);

Spaces must be used for alignment; tabs are not allowed
Open

        $this->skippedData = array_keys($requestKeys);

Spaces must be used for alignment; tabs are not allowed
Open

     *

Spaces must be used for alignment; tabs are not allowed
Open

        unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);

Spaces must be used for alignment; tabs are not allowed
Open

            }

Spaces must be used for alignment; tabs are not allowed
Open

        if ($fieldInfo) {

No space found after comma in function call
Open

        unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);

No space found after comma in function call
Open

        unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);

There are no issues that match your filters.

Category
Status