Avoid using static access to class 'Settings_BusinessHours_Record_Model' in method 'process'. Open
$recordModel = Settings_BusinessHours_Record_Model::getInstanceById($request->getInteger('record'));
- 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\Time' in method 'process'. Open
$recordModel->set('working_hours_to', \App\Fields\Time::formatToDB($request->getByType('working_hours_to', 'TimeInUserFormat', false), false));
- 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 'Settings_Vtiger_Module_Model' in method 'process'. Open
$moduleModel = Settings_Vtiger_Module_Model::getInstance($request->getModule(false));
- 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 'Settings_BusinessHours_Record_Model' in method 'process'. Open
$recordModel = Settings_BusinessHours_Record_Model::getCleanInstance();
- 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 process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$recordModel = Settings_BusinessHours_Record_Model::getCleanInstance();
}
- 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\Time' in method 'process'. Open
$recordModel->set('working_hours_from', \App\Fields\Time::formatToDB($request->getByType('working_hours_from', 'TimeInUserFormat', false), false));
- 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 "timePeriod" 3 times. Open
$recordModel->set('reaction_time', $request->getByType('reaction_time', 'timePeriod'));
- 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 undeclared method \Settings_Vtiger_Module_Model::getListViewUrl
Open
header('location: ' . $moduleModel->getListViewUrl());
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_BusinessHours_Save_Action extends Settings_Vtiger_Basic_Action
- Exclude checks
The class Settings_BusinessHours_Save_Action is not named in CamelCase. Open
class Settings_BusinessHours_Save_Action extends Settings_Vtiger_Basic_Action
{
/**
* Save business hours entry.
*
- Read upRead up
- Exclude checks
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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('location: ' . $moduleModel->getListViewUrl());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \App\Request $request
- 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('idle_time', $request->getByType('idle_time', 'timePeriod'));
- 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('working_hours_from', \App\Fields\Time::formatToDB($request->getByType('working_hours_from', 'TimeInUserFormat', false), false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('working_hours_to', \App\Fields\Time::formatToDB($request->getByType('working_hours_to', 'TimeInUserFormat', false), false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('holidays', $request->getBoolean('holidays') ? 1 : 0);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('resolve_time', $request->getByType('resolve_time', 'timePeriod'));
- 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 = Settings_BusinessHours_Record_Model::getCleanInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('default', $request->getBoolean('default') ? 1 : 0);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$request->isEmpty('record', true)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = Settings_Vtiger_Module_Model::getInstance($request->getModule(false));
- 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
* Save business hours entry.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$workingDays = $request->getArray('working_days', 'Integer');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('working_days', implode(',', $workingDays));
- Exclude checks
Line exceeds 120 characters; contains 155 characters Open
$recordModel->set('working_hours_from', \App\Fields\Time::formatToDB($request->getByType('working_hours_from', 'TimeInUserFormat', false), false));
- 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
$recordModel = Settings_BusinessHours_Record_Model::getInstanceById($request->getInteger('record'));
- Exclude checks
Line exceeds 120 characters; contains 151 characters Open
$recordModel->set('working_hours_to', \App\Fields\Time::formatToDB($request->getByType('working_hours_to', 'TimeInUserFormat', false), false));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('name', $request->getByType('name', 'Text'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('reaction_time', $request->getByType('reaction_time', 'timePeriod'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Class name "Settings_BusinessHours_Save_Action" is not in camel caps format Open
class Settings_BusinessHours_Save_Action extends Settings_Vtiger_Basic_Action
- Exclude checks