Psalm cleanup pass.

This commit is contained in:
Andrey Savchenko committed 2019-06-15 10:11:50 +03:00
1 parent cc1cdc577a
commit 1e9a600096
10 files changed
+58 -37

No files matched your search

+15 -3
View File
@@ -20,13 +20,19 @@ class Hook_Collector extends Stopwatch_Collector {
/** @var array $events */
protected $events = [];
/** @var array */
/**
* @var array $callbacks
* @psalm-var array<string, \WP_Hook> $callbacks
*/
protected $callbacks = [];
/** @var Hook_Formatter */
protected $formatter;
/** @var array $calls Tracks number of calls for recurrent events. */
/**
* @var array $calls Tracks number of calls for recurrent events.
* @psalm-var array<string, int> $calls
*/
private $calls = [];
/**
@@ -55,7 +61,7 @@ class Hook_Collector extends Stopwatch_Collector {
/**
* Time the point between network/MU plugins and regular if network activated.
*/
public function muplugins_loaded() {
public function muplugins_loaded(): void {
$this->stop( 'Network & MU Plugins Load' );
$this->start( 'Plugins Load', 'plugin' );
}
@@ -97,6 +103,9 @@ class Hook_Collector extends Stopwatch_Collector {
* @param string|null $stop Stop hook name (defaults to start name). Pass empty string to ignore.
* @param int $start_priority Start hook priority (defaults to -1).
* @param int $stop_priority Stop hook priority (defaults to max int).
*
* @psalm-suppress MissingClosureReturnType
* @psalm-suppress MissingClosureParamType
*/
private function add_event(
string $event,
@@ -116,11 +125,13 @@ class Hook_Collector extends Stopwatch_Collector {
$event .= $this->get_count_suffix( $event, true );
if ( 'Sidebar' === $event ) {
/** @var string $input */
$event = $input;
}
if ( $start === $stop ) {
global $wp_filter;
/** @psalm-var array<string, \WP_Hook> $wp_filter */
$this->callbacks[ $event ] = $wp_filter[ $start ];
}
@@ -136,6 +147,7 @@ class Hook_Collector extends Stopwatch_Collector {
$event .= $this->get_count_suffix( $event );
if ( 'Sidebar' === $event ) {
/** @var string $input */
$event = $input;
}
+5 -2
View File
@@ -16,7 +16,10 @@ class Http_Collector extends Stopwatch_Collector {
/** @var Backtrace_Formatter */
private $formatter;
/** @var array */
/**
* @var array $callers
* @psalm-var array<string, string> $callers
*/
private $callers = [];
/**
@@ -39,7 +42,7 @@ class Http_Collector extends Stopwatch_Collector {
* @param array $args HTTP request arguments.
* @param string $url The request URL.
*
* @return boolean
* @return false|array|\WP_Error
*/
public function pre_http_request( $false, array $args, string $url ) {
@@ -54,10 +54,8 @@ class Plugin_Load_Collector implements Record_Collector_Interface {
* Converts recorded information into a Record instance.
*
* @param array $entry Data entry for the plugin.
*
* @return Record_Interface
*/
private function create_record( array $entry ): Record_Interface {
private function create_record( array $entry ): Record {
return new Record(
plugin_basename( $entry['name'] ),
$entry['origin'],
+4
View File
@@ -8,6 +8,8 @@ use Rarst\Laps\Record\Record;
/**
* Processes SQL events from data logged by wpdb.
*
* @template QueryData as array{0: string, 1: float, 2: string, 3: float}
*/
class Sql_Collector implements Record_Collector_Interface {
@@ -59,11 +61,13 @@ class Sql_Collector implements Record_Collector_Interface {
global $wpdb;
/** @psalm-suppress MixedPropertyFetch */
if ( empty( $wpdb->queries ) ) {
return [];
}
/** @var array $wpdb->queries */
/** @psalm-var array<int, QueryData> $wpdb->queries */
$records = array_filter( array_map( [ $this, 'transform' ], array_keys( $wpdb->queries ), $wpdb->queries ) );
return $records;
@@ -51,6 +51,7 @@ class Stopwatch_Collector implements Record_Collector_Interface {
*/
public function get_records(): array {
/** @psalm-var array<string, StopwatchEvent> $events */
$events = $this->stopwatch->getSectionEvents( '__root__' );
/** @var string $name */