The class EventHandler has an overall complexity of 51 which is very high. The configured complexity threshold is 50. Open
class EventHandler
{
/**
* Table name.
*
- Exclude checks
File EventHandler.php
has 300 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace App;
/**
EventHandler
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
class EventHandler
{
/**
* Table name.
*
Function getByType
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public static function getByType(string $name, ?string $moduleName = '', bool $active = true): array
{
$handlersByType = [];
$cacheName = 'All' . ($active ? ':active' : '');
if (Cache::has('EventHandlerByType', $cacheName)) {
- 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 registerHandler
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
public static function registerHandler(string $eventName, string $className, $includeModules = '', $excludeModules = '', $priority = 5, $isActive = true, $ownerId = 0, $mode = 1): bool
Function getVarsByType
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function getVarsByType(string $name, string $moduleName, array $params, bool $byKey = false): string
{
$return = [];
foreach (self::getByType($name, $moduleName) as $key => $handler) {
$className = $handler['handler_class'];
- 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
Function checkActive
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function checkActive(string $className, ?string $eventName = null): bool
{
$rows = (new \App\Db\Query())->from(self::$baseTable)->where(['handler_class' => $className])->all();
$status = false;
foreach ($rows as $row) {
- 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
Function getHandlers
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getHandlers(string $name): array
{
$handlers = static::getByType($name, $this->moduleName);
if ($this->exceptions['disableHandlers'] ?? null) {
$handlers = array_intersect_key($handlers, array_flip(self::$mandatoryEventClass));
- 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 getByType() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public static function getByType(string $name, ?string $moduleName = '', bool $active = true): array
{
$handlersByType = [];
$cacheName = 'All' . ($active ? ':active' : '');
if (Cache::has('EventHandlerByType', $cacheName)) {
- 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
This function has 8 parameters, which is greater than the 7 authorized. Open
public static function registerHandler(string $eventName, string $className, $includeModules = '', $excludeModules = '', $priority = 5, $isActive = true, $ownerId = 0, $mode = 1): bool
- Read upRead up
- Exclude checks
A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.
Noncompliant Code Example
With a maximum number of 4 parameters:
function doSomething($param1, $param2, $param3, $param4, $param5) { ... }
Compliant Solution
function doSomething($param1, $param2, $param3, $param4) { ... }
Class "EventHandler" has 22 methods, which is greater than 20 authorized. Split it into smaller classes. Open
class EventHandler
- Read upRead up
- Exclude checks
A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.
The method setInActive has a boolean flag argument $eventName, which is a certain sign of a Single Responsibility Principle violation. Open
public static function setInActive($className, $eventName = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '298', column '16'). Open
$rows = (new \App\Db\Query())->from(self::$baseTable)->where(['handler_class' => $className])->all();
- 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 getAll has a boolean flag argument $active, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getAll(bool $active = true): array
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method registerHandler has a boolean flag argument $isActive, which is a certain sign of a Single Responsibility Principle violation. Open
public static function registerHandler(string $eventName, string $className, $includeModules = '', $excludeModules = '', $priority = 5, $isActive = true, $ownerId = 0, $mode = 1): bool
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '147', column '17'). Open
$query = (new \App\Db\Query())->from(self::$baseTable)->orderBy(['priority' => SORT_DESC]);
- 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 deleteHandler has a boolean flag argument $eventName, which is a certain sign of a Single Responsibility Principle violation. Open
public static function deleteHandler($className, $eventName = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '494', column '14'). Open
throw new \App\Exceptions\AppException('LBL_HANDLER_NOT_FOUND');
- 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 getVarsByType has a boolean flag argument $byKey, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getVarsByType(string $name, string $moduleName, array $params, bool $byKey = false): string
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method setActive has a boolean flag argument $eventName, which is a certain sign of a Single Responsibility Principle violation. Open
public static function setActive($className, $eventName = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
The method getByType has a boolean flag argument $active, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getByType(string $name, ?string $moduleName = '', bool $active = true): array
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '229', column '20'). Open
$isExists = (new \App\Db\Query())->from(self::$baseTable)->where(['event_name' => $eventName, 'handler_class' => $className])->exists();
- 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 'App\Cache' in method 'getByType'. Open
Cache::save('EventHandlerByType', $cacheName, $handlersByType, Cache::LONG);
- 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\Purifier' in method 'getVarsByType'. Open
return Purifier::encodeHtml(Json::encode($return));
- 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 triggerHandler uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$handler = $this->handlers[$className] = new $className();
}
- 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
The method getByType uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
foreach (self::getAll($active) as $handler) {
$handlersByType[$handler['event_name']][$handler['handler_class']] = $handler;
}
Cache::save('EventHandlerByType', $cacheName, $handlersByType, Cache::LONG);
- 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\Cache' in method 'clearCache'. Open
Cache::delete('EventHandlerByType', 'All');
- 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 getVarsByType uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$return = array_values(array_unique(array_merge($return, $vars)));
}
- 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\Cache' in method 'clearCache'. Open
Cache::delete('EventHandlerByType', 'All:active');
- 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\Log' in method 'triggerHandler'. Open
Log::error("Handler not found, class: {$className} | {$function}");
- 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 assigning values to variables in if clauses and the like (line '201', column '46'). Open
public static function getVarsByType(string $name, string $moduleName, array $params, bool $byKey = false): string
{
$return = [];
foreach (self::getByType($name, $moduleName) as $key => $handler) {
$className = $handler['handler_class'];
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '457', column '13'). Open
public function getHandlers(string $name): array
{
$handlers = static::getByType($name, $this->moduleName);
if ($this->exceptions['disableHandlers'] ?? null) {
$handlers = array_intersect_key($handlers, array_flip(self::$mandatoryEventClass));
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class 'App\Cache' in method 'getByType'. Open
$handlersByType = Cache::get('EventHandlerByType', $cacheName);
- 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\Cache' in method 'getByType'. Open
if (Cache::has('EventHandlerByType', $cacheName)) {
- 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\Json' in method 'getVarsByType'. Open
return Purifier::encodeHtml(Json::encode($return));
- 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 "modulesExcluded" 8 times. Open
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- 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 "include_modules" 3 times. Open
if ((!empty($handler['include_modules']) && !\in_array($moduleName, explode(',', $handler['include_modules']))) || (!empty($handler['exclude_modules']) && \in_array($moduleName, explode(',', $handler['exclude_modules'])))) {
- 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 "active" 8 times. Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- 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 "event_name" 8 times. Open
$handlersByType[$handler['event_name']][$handler['handler_class']] = $handler;
- 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 "columns" 8 times. Open
'columns' => [
- 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 "eventName" 8 times. Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- 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 "eventDescription" 8 times. Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- 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 "EventHandlerByType" 5 times. Open
if (Cache::has('EventHandlerByType', $cacheName)) {
- 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 "LBL_EVENT_DESC" 8 times. Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- 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.
Rename "$handlers" which has the same name as the field declared at line 28. Open
$handlers = static::getByType($name, $this->moduleName);
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Define a constant instead of duplicating this literal "is_active" 5 times. Open
$query->where(['is_active' => 1]);
- 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 "exclude_modules" 3 times. Open
if ((!empty($handler['include_modules']) && !\in_array($moduleName, explode(',', $handler['include_modules']))) || (!empty($handler['exclude_modules']) && \in_array($moduleName, explode(',', $handler['exclude_modules'])))) {
- 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 "LBL_EVENT_NAME" 8 times. Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- 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 "LBL_INCLUDE_MODULES" 8 times. Open
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- 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 "modules" 8 times. Open
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- 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 "LBL_EXCLUDE_MODULES" 8 times. Open
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- 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 "label" 48 times. Open
'label' => 'LBL_EDIT_VIEW_PRESAVE',
- 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 "LBL_EVENT_IS_ACTIVE" 8 times. Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- 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 "handler_class" 9 times. Open
$handlersByType[$handler['event_name']][$handler['handler_class']] = $handler;
- 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 \App\Db::createCommand
Open
$return = \App\Db::getInstance()->createCommand()
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()->delete(self::$baseTable, $params)->execute();
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$isExists = (new \App\Db\Query())->from(self::$baseTable)->where(['event_name' => $eventName, 'handler_class' => $className])->exists();
- Exclude checks
Doc-block of $moduleName
in getByType
is phpdoc param type string
which is not a permitted replacement of the nullable param type ?string
declared in the signature ('?T' should be documented as 'T|null' or '?T') Open
* @param string $moduleName
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
Db::getInstance()->createCommand()->update(self::$baseTable, $params, ['eventhandler_id' => $id])->execute();
- Exclude checks
Saw an @param annotation for params,
but it was not found in the param list of function addParams(mixed $key, mixed $value)
Open
* @param array $params
- Exclude checks
Invalid offset "disableHandlerClasses"
of array type array{}
Open
} elseif ($disableHandlers = $this->exceptions['disableHandlerClasses'] ?? null) {
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()->update(self::$baseTable, ['is_active' => true], $params)->execute();
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$rows = (new \App\Db\Query())->from(self::$baseTable)->where(['handler_class' => $className])->all();
- Exclude checks
Call to method error
from undeclared class \App\Log
Open
Log::error("Handler not found, class: {$className} | {$function}");
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$query = (new \App\Db\Query())->from(self::$baseTable)->orderBy(['priority' => SORT_DESC]);
- Exclude checks
Invalid offset "disableHandlers"
of array type array{}
Open
if ($this->exceptions['disableHandlers'] ?? null) {
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
public static function setInActive($className, $eventName = false)
{
$params = ['handler_class' => $className];
if ($eventName) {
$params['event_name'] = $eventName;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 90.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
public static function setActive($className, $eventName = false)
{
$params = ['handler_class' => $className];
if ($eventName) {
$params['event_name'] = $eventName;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 90.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid variables with short names like $id. Configured minimum length is 3. Open
public static function update(array $params, int $id)
- 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
Spaces must be used to indent lines; tabs are not allowed Open
* @var string
- 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
* Handler types.
- 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
'label' => 'LBL_EDIT_VIEW_PRESAVE',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- 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
'icon' => 'fas fa-pallet',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $exceptions = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const HANDLER_TYPES = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'EditViewPreSave' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- 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
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const EDIT_VIEW_CHANGE_VALUE = 'EditViewChangeValue';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'columns' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'columns' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- 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
'label' => 'LBL_EDIT_VIEW_DUPLICATE',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var int Handler is in system mode, no editing possible */
- 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
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'EntityBeforeSave' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => 'LBL_ENTITY_AFTER_SAVE',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $moduleName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $params;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'icon' => 'fas fa-clone',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- 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
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- 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
* Table name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const SYSTEM = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const RECORD_CONVERTER_AFTER_SAVE = 'RecordConverterAfterSave';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => 'LBL_DETAIL_VIEW_BEFORE',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'icon' => 'mdi mdi-account-details c-mdi',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'EditViewBefore' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- 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
'columns' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'columns' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- 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
'label' => 'LBL_INVENTORY_RECORD_DETAILS',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Edit view, change value */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'columns' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => 'LBL_ENTITY_CHANGE_STATE',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'label' => 'LBL_EDIT_VIEW_BEFORE',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- 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
private static $mandatoryEventClass = ['ModTracker_ModTrackerHandler_Handler'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var int Handler is in edit mode */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'EntityChangeState' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- 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
'label' => 'LBL_ENTITY_BEFORE_SAVE',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'icon' => 'yfi yfi-full-editing-view ',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'columns' => [
- 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
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'columns' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- 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 const EDITABLE = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventName' => ['label' => 'LBL_EVENT_NAME'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'eventDescription' => ['label' => 'LBL_EVENT_DESC'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $handlers = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const EDIT_VIEW_PRE_SAVE = 'EditViewPreSave';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'icon' => 'fas fa-step-backward',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected static $baseTable = 'vtiger_eventhandlers';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Edit view, validation before saving */
- 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
'icon' => 'far fa-save',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'active' => ['label' => 'LBL_EVENT_IS_ACTIVE'],
- 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
/** @var string Record converter after create record */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'icon' => 'fas fa-save',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'EditViewDuplicate' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $recordModel;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'icon' => 'fas fa-compass',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'EntityAfterSave' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'columns' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'InventoryRecordDetails' => [
- 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
if ($active) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $byKey
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return[$key] = $vars;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->insert(self::$baseTable, [
- 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
* Unregister a registered handler.
- 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
Cache::save('EventHandlerByType', $cacheName, $handlersByType, Cache::LONG);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $eventName The name of the event to handle
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'handler_class' => $className,
- 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 ($eventName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modulesExcluded' => ['label' => 'LBL_EXCLUDE_MODULES'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'DetailViewBefore' => [
- 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
'modules' => ['label' => 'LBL_INCLUDE_MODULES'],
- 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
foreach ($handlers as $key => $handler) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getVarsByType(string $name, string $moduleName, array $params, bool $byKey = false): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return Purifier::encodeHtml(Json::encode($return));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'include_modules' => $includeModules,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function clearCache(): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Cache::delete('EventHandlerByType', 'All:active');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (self::getByType($name, $moduleName) as $key => $handler) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$className = $handler['handler_class'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $priority
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'priority' => $priority,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool|string $eventName
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function deleteHandler($className, $eventName = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Db::getInstance()->createCommand()->update(self::$baseTable, $params, ['eventhandler_id' => $id])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::clearCache();
- 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
* Get all event handlers.
- 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
$query = (new \App\Db\Query())->from(self::$baseTable)->orderBy(['priority' => SORT_DESC]);
- 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
if (Cache::has('EventHandlerByType', $cacheName)) {
- 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 ($moduleName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 240 characters Open
if ((!empty($handler['include_modules']) && !\in_array($moduleName, explode(',', $handler['include_modules']))) || (!empty($handler['exclude_modules']) && \in_array($moduleName, explode(',', $handler['exclude_modules'])))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $params
- 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
unset($handlers[$key]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $isActive
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = \App\Db::getInstance()->createCommand()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $name
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params = ['handler_class' => $className];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- 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
* @return void
- 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
$params['event_name'] = $eventName;
- 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 (method_exists($className, 'vars') && ($vars = (new $className())->vars($name, $params, $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
* Register an event handler.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $includeModules
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $excludeModules
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'is_active' => $isActive,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Clear cache.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $params
- 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
* @param string $className
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $mode
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function registerHandler(string $eventName, string $className, $includeModules = '', $excludeModules = '', $priority = 5, $isActive = true, $ownerId = 0, $mode = 1): bool
- 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
\App\Db::getInstance()->createCommand()->delete(self::$baseTable, $params)->execute();
- 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 static function getAll(bool $active = true): array
- 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
* @param bool $active
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getByType(string $name, ?string $moduleName = '', bool $active = true): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$cacheName = 'All' . ($active ? ':active' : '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 188 characters Open
public static function registerHandler(string $eventName, string $className, $includeModules = '', $excludeModules = '', $priority = 5, $isActive = true, $ownerId = 0, $mode = 1): bool
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
$isExists = (new \App\Db\Query())->from(self::$baseTable)->where(['event_name' => $eventName, 'handler_class' => $className])->exists();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'event_name' => $eventName,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Update an event handler.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param 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
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (self::getAll($active) as $handler) {
- 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 = array_values(array_unique(array_merge($return, $vars)));
- 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
'owner_id' => $ownerId,
- 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
static::clearCache();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function update(array $params, 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ((!empty($handler['include_modules']) && !\in_array($moduleName, explode(',', $handler['include_modules']))) || (!empty($handler['exclude_modules']) && \in_array($moduleName, explode(',', $handler['exclude_modules'])))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($byKey) {
- 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
$isExists = (new \App\Db\Query())->from(self::$baseTable)->where(['event_name' => $eventName, 'handler_class' => $className])->exists();
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $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
$handlersByType = Cache::get('EventHandlerByType', $cacheName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $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
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $active
- 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
$query->where(['is_active' => 1]);
- 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
$handlersByType = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$handlers = $handlersByType[$name] ?? [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $handlers;
- 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
*/
- 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
return $query->indexBy('eventhandler_id')->all();
- 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 (!$isExists) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'exclude_modules' => $excludeModules,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'privileges' => $mode,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Cache::delete('EventHandlerByType', 'All');
- 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
* Check if it is active function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $className
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rows = (new \App\Db\Query())->from(self::$baseTable)->where(['handler_class' => $className])->all();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return 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
* @param bool|string $eventName
- 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 $this
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->moduleName = $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 getModuleName()
- 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 exceptions.
- 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 setExceptions(array $exceptions)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $name Event name
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get active event handlers by type (event_name).
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $name
- 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
* Get vars event handlers by type (event_name).
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $ownerId
- 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
* @param string $className
- 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
$handlersByType[$handler['event_name']][$handler['handler_class']] = $handler;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::clearCache();
- 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
if (isset($eventName) && $eventName !== $row['event_name']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $className
- 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
$params['event_name'] = $eventName;
- 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->moduleName = $recordModel->getModuleName();
- 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 $this->params[$key] ?? null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$status = true;
- 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
static::clearCache();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \Vtiger_Record_Model $recordModel
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setModuleName($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
* @param mixed $value
- 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 addParams($key, $value)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- 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
public static function setActive($className, $eventName = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return $this
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->recordModel = $recordModel;
- 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->params[$key] = $value;
- 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
* @param string|null $eventName
- 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 (empty($row['is_active'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Db::getInstance()->createCommand()->update(self::$baseTable, ['is_active' => true], $params)->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::clearCache();
- 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 module name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get module name.
- 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->exceptions = $exceptions;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- 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
}
- 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 record model.
- 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
* @param array $exceptions
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($eventName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->update(self::$baseTable, ['is_active' => false], $params)->execute();
- 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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $params
- 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
* @param mixed $key
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function checkActive(string $className, ?string $eventName = null): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $status;
- 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
$params = ['handler_class' => $className];
- 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
* Get record model.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getRecordModel()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array Additional parameters
- 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
* Trigger an event.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->getHandlers($name) as $handler) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$status = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $className
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($eventName) {
- 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 $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->params = $params;
- 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
$function = lcfirst($handler['event_name']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Db::getInstance()->createCommand()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setRecordModel(\Vtiger_Record_Model $recordModel)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $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
* @param array $params
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->recordModel;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getParam(string $key)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->exceptions['disableHandlers'] ?? null) {
- 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
* Set an event handler as inactive.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set params.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Add param.
- 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 \Vtiger_Record_Model
- 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
$handlers = static::getByType($name, $this->moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$className = $handler['handler_class'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params = ['handler_class' => $className];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set an event handler as active.
- 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
}
- 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 $this->params;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getHandlers(string $name): array
- 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
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$params['event_name'] = $eventName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool|string $eventName
- 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 setParams($params)
- 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 $this->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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($rows as $row) {
- 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
*
- 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
$handlers = array_intersect_key($handlers, array_flip(self::$mandatoryEventClass));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($handlers[$className])) {
- 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 static function setInActive($className, $eventName = 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
* Get params.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getParams()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $handlers;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function trigger(string $name)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Log::error("Handler not found, class: {$className} | {$function}");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$handler = $this->handlers[$className];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $handler
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function triggerHandler(array $handler)
- 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
* Trigger handler.
- 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
* @param string $name Event name
- 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
* @throws \App\Exceptions\AppException
- 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 (!method_exists($className, $function)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException('LBL_HANDLER_NOT_FOUND');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($disableHandlers as $className) {
- 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
* @throws \App\Exceptions\AppException
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get param.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $key
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return mixed
- 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 array Handlers list
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($disableHandlers = $this->exceptions['disableHandlerClasses'] ?? null) {
- 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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($this->handlers[$className])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $handler->{$function}($this);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($handlers[$className]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$handler = $this->handlers[$className] = new $className();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->triggerHandler($handler);
- Exclude checks