Refactor Loghandler crandom function to avoid closure in constructor
[MAILPOET-2444]
This commit is contained in:
committed by
Jack Kitterhing
parent
f11774156c
commit
d3345d35d0
@ -19,18 +19,12 @@ class LogHandler extends AbstractProcessingHandler {
|
||||
*/
|
||||
const DAYS_TO_KEEP_LOGS = 30;
|
||||
|
||||
/** @var callable */
|
||||
/** @var callable|null */
|
||||
private $rand_function;
|
||||
|
||||
public function __construct($level = \MailPoetVendor\Monolog\Logger::DEBUG, $bubble = \true, $rand_function = null) {
|
||||
parent::__construct($level, $bubble);
|
||||
if (!$rand_function) {
|
||||
$this->rand_function = function($min, $max) {
|
||||
return rand($min, $max);
|
||||
};
|
||||
} else {
|
||||
$this->rand_function = $rand_function;
|
||||
}
|
||||
$this->rand_function = $rand_function;
|
||||
}
|
||||
|
||||
protected function write(array $record) {
|
||||
@ -53,7 +47,10 @@ class LogHandler extends AbstractProcessingHandler {
|
||||
}
|
||||
|
||||
private function getRandom() {
|
||||
return call_user_func($this->rand_function, 0, 100);
|
||||
if ($this->rand_function) {
|
||||
return call_user_func($this->rand_function, 0, 100);
|
||||
}
|
||||
return rand(0, 100);
|
||||
}
|
||||
|
||||
private function purgeOldLogs() {
|
||||
|
Reference in New Issue
Block a user