Method duplicate
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function duplicate(App\Request $request)
{
$response = new Vtiger_Response();
$moduleName = $request->getModule(false);
$result = true;
Function duplicate
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function duplicate(App\Request $request)
{
$response = new Vtiger_Response();
$moduleName = $request->getModule(false);
$result = true;
- 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
Method save
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function save(App\Request $request)
{
$response = new Vtiger_Response();
$moduleName = $request->getModule(false);
$result = true;
Method massDelete
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function massDelete(App\Request $request)
{
$response = new Vtiger_Response();
$moduleName = $request->getModule(false);
$result = true;
Function save
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function save(App\Request $request)
{
$response = new Vtiger_Response();
$moduleName = $request->getModule(false);
$result = true;
- 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
The method save() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function save(App\Request $request)
{
$response = new Vtiger_Response();
$moduleName = $request->getModule(false);
$result = true;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed. Open
public function save(App\Request $request)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Missing class import via use statement (line '28', column '19'). Open
$response = new Vtiger_Response();
- 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 '72', column '19'). Open
$response = new Vtiger_Response();
- 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 '123', column '19'). Open
$response = new Vtiger_Response();
- 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 '156', column '19'). Open
$response = new Vtiger_Response();
- 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
The method save uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = false;
$message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);
}
- 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\Language' in method 'save'. Open
$message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);
- 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 save uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);
}
- 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\Language' in method 'massDelete'. Open
\App\Language::translate('LBL_HOLIDAY_DELETE_SOMENOTDELETED', $moduleName);
- 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\Language' in method 'duplicate'. Open
'message' => $message ?: \App\Language::translate('LBL_DUPLICATE_SUCCESS', $moduleName),
- 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\Date' in method 'duplicate'. Open
$notDuplicated[] = \App\Fields\Date::formatToDisplay($sourceDate);
- 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\Language' in method 'delete'. Open
\App\Language::translate('LBL_HOLIDAY_DELETE_OK', $moduleName);
- 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\Language' in method 'delete'. Open
$message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);
- 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_PublicHoliday_Record_Model' in method 'save'. Open
$recordModel = $holidayId ? Settings_PublicHoliday_Record_Model::getInstanceById($holidayId) : Settings_PublicHoliday_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
Avoid using static access to class 'Settings_PublicHoliday_Record_Model' in method 'delete'. Open
$recordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $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
Avoid using static access to class 'Settings_PublicHoliday_Record_Model' in method 'save'. Open
$recordModel = $holidayId ? Settings_PublicHoliday_Record_Model::getInstanceById($holidayId) : Settings_PublicHoliday_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
Avoid using static access to class 'Settings_PublicHoliday_Record_Model' in method 'duplicate'. Open
$sourceRecordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $sourceId);
- 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\Language' in method 'save'. Open
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName) : \App\Language::translate('LBL_NEW_DATE_OK', $moduleName);
- 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\Language' in method 'save'. Open
'message' => $message ?: \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName),
- 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\Date' in method 'save'. Open
$date = App\Fields\Date::formatToDB($date);
- 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\Language' in method 'delete'. Open
\App\Language::translate('LBL_HOLIDAY_DELETE_ALREADYDELETED', $moduleName) :
- 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\Language' in method 'massDelete'. Open
$message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);
- 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\Language' in method 'save'. Open
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName) : \App\Language::translate('LBL_NEW_DATE_OK', $moduleName);
- 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\Language' in method 'save'. Open
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);
- 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 delete uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = false;
$message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);
}
- 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 'Settings_PublicHoliday_Record_Model' in method 'massDelete'. Open
$recordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $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
Avoid using static access to class '\App\Language' in method 'massDelete'. Open
\App\Language::translate('LBL_HOLIDAY_DELETE_OK', $moduleName) :
- 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\Language' in method 'save'. Open
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);
- 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 massDelete uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = false;
$message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);
}
- 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\Language' in method 'save'. Open
$message = $request->getByType('holidayDate', 'Text') . '<br />' . \App\Language::translate('LBL_DATE_EXISTS', $moduleName);
- 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\Language' in method 'duplicate'. Open
$message = \App\Language::translate('LBL_DUPLICATE_ERROR', $moduleName) . ' ' . $targetYear . '<br />' . implode(', ', $notDuplicated);
- 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 duplicate uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result = false;
$message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);
}
- 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\Language' in method 'duplicate'. Open
$message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);
- 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_PublicHoliday_Record_Model' in method 'duplicate'. Open
$targetRecordModel = Settings_PublicHoliday_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
Define a constant instead of duplicating this literal "success" 4 times. Open
'success' => $result,
- 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 "message" 4 times. Open
'message' => $message ?: \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName),
- 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 with 0 arg(s) to \Settings_PublicHoliday_Holiday_Action::save()
which requires 1 arg(s) defined at /code/modules/Settings/PublicHoliday/actions/Holiday.php:26
Open
if ($targetRecordModel->isDuplicate() || !$targetRecordModel->save()) {
- Exclude checks
Method \Settings_PublicHoliday_Holiday_Action::delete
is declared to return \none
but has no return value Open
public function delete(App\Request $request)
- Exclude checks
Return type of delete()
is undeclared type \none
Open
public function delete(App\Request $request)
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_PublicHoliday_Holiday_Action extends Settings_Vtiger_Index_Action
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = !$request->isEmpty('id') ? $request->getInteger('id') : 0;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The class Settings_PublicHoliday_Holiday_Action is not named in CamelCase. Open
class Settings_PublicHoliday_Holiday_Action extends Settings_Vtiger_Index_Action
{
/** {@inheritdoc} */
public function __construct()
{
- 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
$this->exposeMethod('save');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setError($e->getCode(), $e->getMessage());
- 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
$response = new Vtiger_Response();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $id);
- 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
$this->exposeMethod('delete');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = $request->getModule(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('holidaydate', $date)
- 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
$response = new Vtiger_Response();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'holidaytype' => $sourceRecordModel->getType(),
- 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
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Mass delete of holidays.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($records as $id) {
- 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
'message' => $message ?: \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setError($e->getCode(), $e->getMessage());
- 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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response = new Vtiger_Response();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (Exception $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->exposeMethod('massDelete');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName) : \App\Language::translate('LBL_NEW_DATE_OK', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sourceDate = $sourceRecordModel->getDate();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (Throwable $e) {
- 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
$message = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($id) {
- 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
$result = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setError($e->getCode(), $e->getMessage());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
parent::__construct();
- 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
public function save(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = $request->getByType('holidayDate', 'Text') . '<br />' . \App\Language::translate('LBL_DATE_EXISTS', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($sourceIds && $targetYear) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($sourceIds as $sourceId) {
- 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_PublicHoliday_Record_Model::getInstanceById((int) $id);
- 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
$response->setResult([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function __construct()
- 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
$response = new Vtiger_Response();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($recordModel->isDuplicate()) {
- 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
}
- Exclude checks
Line exceeds 120 characters; contains 155 characters Open
$message = \App\Language::translate('LBL_DUPLICATE_ERROR', $moduleName) . ' ' . $targetYear . '<br />' . implode(', ', $notDuplicated);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->emit();
- 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
$result = false;
- 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
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult([
- 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
public function delete(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'success' => $result,
- 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
->set('holidayname', $name)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = $request->getModule(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'holidaydate' => $targetDate,
- 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
if ($notDuplicated) {
- 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 none
- 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
if (\count($records)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = '';
- Exclude checks
Line exceeds 120 characters; contains 167 characters Open
$recordModel = $holidayId ? Settings_PublicHoliday_Record_Model::getInstanceById($holidayId) : Settings_PublicHoliday_Record_Model::getCleanInstance();
- 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
$sourceIds = $request->getArray('holidayIds', \App\Purifier::INTEGER);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$targetRecordModel->setData([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notDuplicated[] = \App\Fields\Date::formatToDisplay($sourceDate);
- 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
$moduleName = $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
$this->exposeMethod('duplicate');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Saves holiday.
- 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
} elseif ($recordModel->save()) {
- Exclude checks
Line exceeds 120 characters; contains 177 characters Open
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_NOTHINGTOUPDATE', $moduleName) : \App\Language::translate('LBL_NEW_DATE_ERROR', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$notDuplicated = [];
- 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
* Deletes holiday.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'message' => $message,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setError($e->getCode(), $e->getMessage());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function massDelete(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'message' => $message,
- 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
$result = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$date = $request->getByType('holidayDate', 'DateInUserFormat');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$type = $request->getByType('holidayType', \App\Purifier::TEXT);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Line exceeds 120 characters; contains 161 characters Open
$message = $holidayId ? \App\Language::translate('LBL_EDIT_DATE_OK', $moduleName) : \App\Language::translate('LBL_NEW_DATE_OK', $moduleName);
- 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
public function duplicate(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
$targetYear = $request->getByType('targetYear', \App\Purifier::INTEGER);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$targetRecordModel = Settings_PublicHoliday_Record_Model::getCleanInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Language::translate('LBL_HOLIDAY_DELETE_ALREADYDELETED', $moduleName) :
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Language::translate('LBL_HOLIDAY_DELETE_OK', $moduleName);
- 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
'success' => $result,
- 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
/** {@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
$name = $request->getByType('holidayName', \App\Purifier::TEXT);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($date && $type && $name) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = \App\Language::translate('LBL_FILL_FORM_ERROR', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (Throwable $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'holidayname' => $sourceRecordModel->getName(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = 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
$id = !$request->isEmpty('id') ? $request->getInteger('id') : 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$deleteResult = $recordModel->delete();
- 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
\App\Language::translate('LBL_HOLIDAY_DELETE_SOMENOTDELETED', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
$message = $request->getByType('holidayDate', 'Text') . '<br />' . \App\Language::translate('LBL_DATE_EXISTS', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'success' => $result,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$targetDate = date($targetYear . '-m-d', strtotime($sourceDate));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = \App\Language::translate('LBL_DUPLICATE_ERROR', $moduleName) . ' ' . $targetYear . '<br />' . implode(', ', $notDuplicated);
- 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
'message' => $message ?: \App\Language::translate('LBL_DUPLICATE_SUCCESS', $moduleName),
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (Throwable $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
$deletedRecords += $recordModel->delete();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = $deletedRecords === \count($records) ?
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$date = App\Fields\Date::formatToDB($date);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->emit();
- 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
$response->emit();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = 0 === $deleteResult ?
- 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
$message = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$records = !$request->isEmpty('records') ? $request->getArray('records') : [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = $holidayId ? Settings_PublicHoliday_Record_Model::getInstanceById($holidayId) : Settings_PublicHoliday_Record_Model::getCleanInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('holidaytype', $type);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sourceRecordModel = Settings_PublicHoliday_Record_Model::getInstanceById((int) $sourceId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'success' => $result,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = 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
$response->emit();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$holidayId = $request->isEmpty('holidayId', true) ? 0 : $request->getInteger('holidayId');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Duplicates holidays for year.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($targetRecordModel->isDuplicate() || !$targetRecordModel->save()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = $request->getModule(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = \App\Language::translate('LBL_HOLIDAY_DELETE_NOTHINGTODELETE', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$deletedRecords = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Language::translate('LBL_HOLIDAY_DELETE_OK', $moduleName) :
- Exclude checks
Class name "Settings_PublicHoliday_Holiday_Action" is not in camel caps format Open
class Settings_PublicHoliday_Holiday_Action extends Settings_Vtiger_Index_Action
- Exclude checks