1 | <?php |
||
24 | trait AgentTrait |
||
25 | { |
||
26 | /** |
||
27 | * @var array Arguments for `__constructor`. |
||
28 | */ |
||
29 | protected static $constructorArgs; |
||
30 | /** |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected static $agentMode = false; |
||
34 | |||
35 | /** |
||
36 | * Agent constructor. |
||
37 | * |
||
38 | * All arguments from `agent()` method should be duplicated in the constructor, for example: |
||
39 | * ``` |
||
40 | * agent($arg1, …, $arg2)` → `__construct($arg1, …, $arg2) |
||
41 | * ``` |
||
42 | */ |
||
43 | public function __construct() |
||
46 | |||
47 | /** |
||
48 | * Factory method for create object of agent class. |
||
49 | * |
||
50 | * Bitrix calls this method to run agent. Your agents should be registered through |
||
51 | * `\Notamedia\ConsoleJedi\Agent\AgentTask`. All arguments from this method should |
||
52 | * be duplicated in the object constructor: |
||
53 | * |
||
54 | * `agent($arg1, …, $arg2)` → `__construct($arg1, …, $arg2)`. |
||
55 | * |
||
56 | * @return static |
||
57 | * |
||
58 | * @see AgentTask |
||
59 | */ |
||
60 | public static function agent() |
||
69 | |||
70 | /** |
||
71 | * Ping from the agent to inform that it still works correctly. Use this method if your agent |
||
72 | * works more 10 minutes, otherwise Bitrix will be consider your agent as non-working. |
||
73 | * |
||
74 | * Usage: |
||
75 | * ```php |
||
76 | * public function executeAgent($param1, $param2) |
||
77 | * { |
||
78 | * // start a heavy (big) cycle |
||
79 | * |
||
80 | * $this->pingAgent(20, ['executeAgent' => [$param1, $param2]]); |
||
81 | * |
||
82 | * // end of cycle |
||
83 | * } |
||
84 | * ``` |
||
85 | * |
||
86 | * @param int $interval The time in minutes after which the agent will be considered non-working. |
||
87 | * @param array $callChain Array with the call any methods from Agent class. |
||
88 | */ |
||
89 | protected function pingAgent($interval, array $callChain) |
||
112 | |||
113 | /** |
||
114 | * Gets agent name. Use to return this name from the executed method of agent. |
||
115 | * |
||
116 | * Usage: |
||
117 | * ```php |
||
118 | * public function executeAgent($param1, $param2) |
||
119 | * { |
||
120 | * // main logic |
||
121 | * |
||
122 | * return $this->getAgentName(['executeAgent' => [$param1, $param2]]); |
||
123 | * } |
||
124 | * ``` |
||
125 | * |
||
126 | * @param array $callChain Array with the call any methods from Agent class. |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function getAgentName(array $callChain) |
||
134 | |||
135 | /** |
||
136 | * Checks that object running as agent. Object is considered an agent |
||
137 | * if it is created using the static method `agent()`. |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function isAgentMode() |
||
145 | } |
||
146 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.