for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Hhxsv5\LaravelS\Swoole\Traits;
use Hhxsv5\LaravelS\Swoole\Timer\CronJob;
trait TimerTrait
{
use ProcessTitleTrait;
use LaravelTrait;
use LogTrait;
public function addTimerProcess(\swoole_server $swoole, array $config, array $laravelConfig)
if (empty($config['enable']) || empty($config['jobs'])) {
return;
}
$startTimer = function () use ($swoole, $config, $laravelConfig) {
$this->setProcessTitle(sprintf('%s laravels: timer process', $config['process_prefix']));
$this->initLaravel($laravelConfig, $swoole);
foreach ($config['jobs'] as $jobClass) {
if (is_array($jobClass) && isset($jobClass[0])) {
$job = new $jobClass[0](isset($jobClass[1]) ? $jobClass[1] : []);
} else {
$job = new $jobClass();
if (!($job instanceof CronJob)) {
throw new \Exception(sprintf('%s must implement the abstract class %s', get_class($job), CronJob::class));
$timerId = swoole_timer_tick($job->interval(), function () use ($job) {
try {
$job->run();
} catch (\Exception $e) {
$this->logException($e);
});
$job->setTimerId($timerId);
if ($job->isImmediate()) {
swoole_timer_after(1, function () use ($job) {
};
$timerProcess = new \swoole_process($startTimer, false, false);
if ($swoole->addProcess($timerProcess)) {
$swoole->addProcess($timerProcess)
Swoole\Server::addProcess()
This check looks for function or method calls that always return null and whose return value is used.
class A { function getObject() { return null; } } $a = new A(); if ($a->getObject()) {
The method getObject() can return nothing but null, so it makes no sense to use the return value.
getObject()
The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
return $timerProcess;
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.