for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace rOpenDev\Google;
trait SleepTrait
{
/** @var int Time we need to wait between two request * */
protected $sleep = 0;
/**
* Chainable `$waitBetweenRequests` setter.
*
* @return self
*/
public function setSleep($seconds)
$this->sleep = $seconds * 1000000;
return $this;
}
* Return the time the script need to sleep.
* @return int Microseconds
protected function getSleep()
$halfSleep = $this->sleep / 2;
$sleepMin = (int) floor($this->sleep - $halfSleep);
$sleepMax = (int) ceil($this->sleep + $halfSleep);
return rand($sleepMin, $sleepMax);
* Exec sleep.
* @return int The time we rest
public function execSleep()
if ($this->sleep) {
$sleep = $this->getSleep();
usleep($sleep);
return $sleep;
* Exec a half sleep.
public function execHalfSleep()
$sleep = round($this->getSleep() / 2);
$sleep
double
integer
$micro_seconds
usleep()
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
ignore-type
usleep(/** @scrutinizer ignore-type */ $sleep);