Avoid using static access to class 'App\Session' in method 'init'. Open
self::$events = Session::get('processEvents') ?? [];
- 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\Session' in method 'writeSession'. Open
Session::set('processEvents', self::$events);
- 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 "priority" 3 times. Open
if (empty($event['priority'])) {
- 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 "execution" 3 times. Open
if (empty($event['execution'])) {
- 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.
Spaces must be used for alignment; tabs are not allowed Open
* ]);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public static function addEvent(array $event): void
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public static function getEvents(): array
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$priority = array_column($events, 'priority');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'execution' => 'once',
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'type' => 'notify',
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (empty($event['execution'])) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'execution' => 'once',
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
self::writeSession();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
throw new Exceptions\AppException('Incorrect data');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param string $name
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return isset(self::$events[$name]);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($writeSession) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'notify' => [
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'text' => 'test',
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$events = [];
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'type' => 'notify',
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'text' => 'test',
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
self::writeSession();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'type' => 'info' // alert, notice, info, success, error
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ]
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* Get events.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
foreach (self::$events as $name => $row) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
unset(self::$events[$name]);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* alert, notice, info, success, error
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$event['priority'] = 5;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* Remove event.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* Write session data.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
private static function writeSession(): void
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (empty($event['name']) || empty($event['type'])) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (empty($event['priority'])) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public static function removeEvent(string $name): void
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if (isset(self::$events[$name])) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ('once' === $row['execution']) {
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* ]
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
self::$events[$event['name']] = $event;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return $events;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'type' => 'info' // alert, notice, info, success, error
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
unset(self::$events[$name]);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* Has event.
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param array $event
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'notify' => [
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$event['execution'] = 'constant';
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$events[] = $row;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
array_multisort($priority, SORT_DESC, $events);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
Session::set('processEvents', self::$events);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @param string $name
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
public static function hasEvent(string $name): bool
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$writeSession = true;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* 'name' => 'notify test',
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
self::writeSession();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$writeSession = false;
- Exclude checks
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
public static $startTime;
- 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 $requestMode;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* CRM root directory.
- 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
* Request process type.
- Exclude checks
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
* Request start time.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var int
- 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 $rootDirectory;
- 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
* Request mode.
- 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 $processType;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Request process name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $processName;
- 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
* @var string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* 'name' => 'notify test',
- 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
* Add event.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function init(): 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
* @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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$events = Session::get('processEvents') ?? [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static $events = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* App\Process::addEvent([
- 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
* List of events.
- 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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Initialization of events.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- Exclude checks