api/webservice/WebserviceStandard/Save.php
Function getRecordModelFromRequest
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
protected function getRecordModelFromRequest(\App\Request $request)
{
$fieldModelList = $this->record->getModule()->getFields();
$requestKeys = $request->getAllRaw();
unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);
- Read upRead up
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
Open
throw new \Api\Core\Exception('No input data', 406);
- 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 '\Api\Core\Module' in method 'getRecordModelFromRequest'. Open
Open
$fieldInfo = \Api\Core\Module::getApiFieldPermission($request->getModule(), $this->appId);
- 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
Spaces must be used for alignment; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$requestKeys = $request->getAllRaw();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
if ($request->has('inventory') && $this->record->getModule()->isInventory()) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
protected $appId;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
* Constructor removed.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
if ($request->has($fieldName)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
unset($requestKeys[$fieldName]);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
public $skippedData = [];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
* @return void
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
throw new \Api\Core\Exception('No input data', 406);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
foreach ($fieldModelList as $fieldName => $fieldModel) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
/** @var int ID of application. */
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
public function __construct()
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$fieldModelList = $this->record->getModule()->getFields();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$fieldInfo = \Api\Core\Module::getApiFieldPermission($request->getModule(), $this->appId);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$this->record = $record->recordModel;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
unset($requestKeys['inventory']);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
/** @var array Skipped value. */
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
if (!$fieldModel->isWritable()) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
protected function getRecordModelFromRequest(\App\Request $request)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$fieldModel->getUITypeModel()->setValueFromRequest($request, $this->record);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
continue;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
return $this->record;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
if (empty($requestKeys)) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$this->record->initInventoryDataFromRequest($request);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
* Initialization with API data.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
* @param BaseModule\Record|Users\Record $record
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
public function init(\Api\Core\BaseAction $record): void
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
* @author Mariusz Krzaczkowski <m.krzaczkowski@yetiforce.com>
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$this->appId = $record->controller->app['id'];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$this->record->setDataForSave([$fieldInfo['tablename'] => [$fieldInfo['columnname'] => 1]]);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
$this->skippedData = array_keys($requestKeys);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Open
if ($fieldInfo) {
- Exclude checks
No space found after comma in function call Open
Open
unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);
- Exclude checks
No space found after comma in function call Open
Open
unset($requestKeys['module'],$requestKeys['action'],$requestKeys['record']);
- Exclude checks