Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 18 |
BaseRequestLog | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
132 | |
0.00% |
0 / 18 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
start | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
finish | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
getTookMs | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 3 |
|||
getDescription | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
getQueryType | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
formatDescription | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
<?php | |
namespace CirrusSearch; | |
abstract class BaseRequestLog implements RequestLog { | |
/** | |
* @var string | |
*/ | |
protected $description; | |
/** | |
* @var string | |
*/ | |
protected $queryType; | |
/** | |
* @var array | |
*/ | |
protected $extra; | |
/** | |
* @var float|null The timestamp, with ms precision, the request started at | |
*/ | |
protected $startTime; | |
/** | |
* @var float|null The timestamp, with ms precision, the request ended at | |
*/ | |
protected $endTime; | |
/** | |
* @param string $description | |
* @param string $queryType | |
* @param array $extra | |
*/ | |
public function __construct( $description, $queryType, array $extra = [] ) { | |
$this->description = $description; | |
$this->queryType = $queryType; | |
$this->extra = $extra; | |
} | |
public function start() { | |
$this->startTime = microtime( true ); | |
} | |
public function finish() { | |
$this->endTime = microtime( true ); | |
} | |
/** | |
* @return int|null | |
*/ | |
public function getTookMs() { | |
if ( $this->startTime && $this->endTime ) { | |
return intval( 1000 * ( $this->endTime - $this->startTime ) ); | |
} else { | |
return null; | |
} | |
} | |
/** | |
* @return string | |
*/ | |
public function getDescription() { | |
return $this->description; | |
} | |
/** | |
* @return string | |
*/ | |
public function getQueryType() { | |
return $this->queryType; | |
} | |
/** | |
* Perform a quick and dirty replacement for $this->description | |
* when it's not going through monolog. It replaces {foo} with | |
* the value of foo | |
* | |
* @return string | |
*/ | |
public function formatDescription() { | |
$pairs = []; | |
// @todo inefficient, getLogVariables may be doing work | |
// that gets done multiple times. | |
foreach ( $this->getLogVariables() as $key => $value ) { | |
if ( is_scalar( $value ) ) { | |
$pairs['{' . $key . '}'] = $value; | |
} | |
} | |
return strtr( $this->description, $pairs ); | |
} | |
} |