Added psalm configuration and refined source.
This commit is contained in:
1 parent
4013046e4f
commit
70de78b276
13 files changed
+82
-4
No files matched your search
@@ -27,6 +27,10 @@ class Core_Load_Collector implements Record_Collector_Interface {
|
||||
|
||||
$request_time = filter_var( $_SERVER['REQUEST_TIME_FLOAT'], FILTER_VALIDATE_FLOAT );
|
||||
|
||||
/**
|
||||
* @var float $request_time
|
||||
* @var float $timestart
|
||||
*/
|
||||
return [
|
||||
new Record( 'PHP Load', $request_time, $timestart - $request_time, '', 'php' ),
|
||||
// TODO This includes network plugins on multisite, need conditional label if Laps is network–activated.
|
||||
|
||||
@@ -18,8 +18,8 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
|
||||
protected $events = [];
|
||||
|
||||
/**
|
||||
* @param Stopwatch $stopwatch Stopwatch instance.
|
||||
* @param array $event_configs Starts and stops configuration.
|
||||
* @param Stopwatch $stopwatch Stopwatch instance.
|
||||
* @param Hook_Event_Config_Interface[] $event_configs Starts and stops configuration.
|
||||
*/
|
||||
public function __construct( Stopwatch $stopwatch, array $event_configs ) {
|
||||
|
||||
@@ -42,7 +42,12 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
|
||||
|
||||
$this->events = array_merge( $this->events, $stops );
|
||||
|
||||
/**
|
||||
* @var string $hook_name
|
||||
* @var array $data
|
||||
*/
|
||||
foreach ( $stops as $hook_name => $data ) {
|
||||
/** @var int $priority */
|
||||
foreach ( array_keys( $data ) as $priority ) {
|
||||
add_action( $hook_name, [ $this, 'tick' ], $priority );
|
||||
}
|
||||
@@ -70,8 +75,14 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
|
||||
|
||||
global $wp_filter;
|
||||
|
||||
/** @var string $filter_name */
|
||||
$filter_name = current_filter();
|
||||
/**
|
||||
* @var \WP_Hook|array $filter_instance
|
||||
* @var array<string,\WP_hook|array> $wp_filter
|
||||
*/
|
||||
$filter_instance = $wp_filter[ $filter_name ];
|
||||
/** @var int $priority */
|
||||
$priority = $filter_instance instanceof \WP_Hook ? $filter_instance->current_priority() : key( $filter_instance );
|
||||
|
||||
// See https://core.trac.wordpress.org/ticket/41185 on broken priority, but more general sanity check.
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Rarst\Laps\Record;
|
||||
*/
|
||||
class Recursive_Record_Iterator extends \ArrayIterator implements \RecursiveIterator {
|
||||
|
||||
/** @var array $children */
|
||||
/** @var Record_Interface[] $children */
|
||||
protected $children = [];
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,12 +34,15 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
* @param string $query SQL query.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @psalm-suppress MixedPropertyFetch
|
||||
*/
|
||||
public function query( $query ): string {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
if ( empty( $this->query_starts ) && ! empty( $wpdb->queries ) ) {
|
||||
/** @var array $wpdb->queries */
|
||||
$this->query_starts[ count( $wpdb->queries ) ] = microtime( true );
|
||||
} else {
|
||||
$this->query_starts[] = microtime( true );
|
||||
@@ -59,6 +62,7 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
/** @var array $wpdb->queries */
|
||||
return array_map( [ $this, 'transform' ], array_keys( $wpdb->queries ), $wpdb->queries );
|
||||
}
|
||||
|
||||
@@ -75,6 +79,7 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
*
|
||||
* @param int $key Query key in captured data.
|
||||
* @param array $query_data Array of captured query data.
|
||||
* @psalm-param array{0: string, 1: float, 2: string} $query_data
|
||||
*
|
||||
* @return Record
|
||||
*/
|
||||
@@ -84,6 +89,7 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
|
||||
[ $sql, $duration, $caller ] = $query_data;
|
||||
|
||||
/** @var float $query_start */
|
||||
$query_start = $this->query_starts[ $key ] ?? $last_query_end;
|
||||
$sql = trim( $sql );
|
||||
$category = 'sql-read';
|
||||
|
||||
@@ -52,6 +52,7 @@ class Stopwatch_Record_Collector implements Record_Collector_Interface {
|
||||
|
||||
$events = $this->stopwatch->getSectionEvents( '__root__' );
|
||||
|
||||
/** @var string $name */
|
||||
foreach ( array_keys( $events ) as $name ) {
|
||||
if ( $this->stopwatch->isStarted( $name ) ) {
|
||||
unset( $events[ $name ] );
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace Rarst\Laps\Record;
|
||||
|
||||
/**
|
||||
* Processes records into sets for display by template.
|
||||
*
|
||||
* @psalm-suppress PropertyNotSetInConstructor
|
||||
*/
|
||||
class Timeline_Iterator implements \Iterator {
|
||||
|
||||
@@ -22,6 +24,8 @@ class Timeline_Iterator implements \Iterator {
|
||||
|
||||
/**
|
||||
* @param Recursive_Record_Iterator $iterator Record iterator.
|
||||
*
|
||||
* @psalm-suppress PossiblyFalsePropertyAssignmentValue
|
||||
*/
|
||||
public function __construct( Recursive_Record_Iterator $iterator ) {
|
||||
|
||||
@@ -36,6 +40,7 @@ class Timeline_Iterator implements \Iterator {
|
||||
|
||||
$data = [];
|
||||
|
||||
/** @var Record $record */
|
||||
foreach ( $this->current as $record ) {
|
||||
$data[] = $this->prepare( $record );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user