Psalm cleanup pass.
This commit is contained in:
1 parent
cc1cdc577a
commit
1e9a600096
10 files changed
+58
-37
No files matched your search
@@ -16,28 +16,14 @@
|
|||||||
<issueHandlers>
|
<issueHandlers>
|
||||||
<LessSpecificReturnType errorLevel="info"/>
|
<LessSpecificReturnType errorLevel="info"/>
|
||||||
<UndefinedFunction errorLevel="suppress"/>
|
<UndefinedFunction errorLevel="suppress"/>
|
||||||
<UndefinedClass>
|
<UndefinedClass errorLevel="suppress"/>
|
||||||
<errorLevel type="suppress">
|
<UndefinedDocblockClass errorLevel="suppress"/>
|
||||||
<referencedClass name="WP_Admin_Bar"/>
|
|
||||||
<referencedClass name="WP_Error"/>
|
|
||||||
<referencedClass name="WP_Hook"/>
|
|
||||||
</errorLevel>
|
|
||||||
</UndefinedClass>
|
|
||||||
<MixedArgument>
|
<MixedArgument>
|
||||||
<errorLevel type="suppress">
|
<errorLevel type="suppress">
|
||||||
<file name="src/Provider/Record_Provider.php" />
|
<file name="src/Provider/Record_Provider.php" />
|
||||||
<file name="src/Record/Collector/Hook_Collector.php" />
|
<file name="src/Provider/Manager_Provider.php" />
|
||||||
|
<!-- <file name="src/Record/Collector/Hook_Collector.php" />-->
|
||||||
</errorLevel>
|
</errorLevel>
|
||||||
</MixedArgument>
|
</MixedArgument>
|
||||||
<MissingClosureParamType>
|
|
||||||
<errorLevel type="suppress">
|
|
||||||
<file name="src/Record/Collector/Hook_Collector.php" />
|
|
||||||
</errorLevel>
|
|
||||||
</MissingClosureParamType>
|
|
||||||
<MissingClosureReturnType>
|
|
||||||
<errorLevel type="suppress">
|
|
||||||
<file name="src/Record/Collector/Hook_Collector.php" />
|
|
||||||
</errorLevel>
|
|
||||||
</MissingClosureReturnType>
|
|
||||||
</issueHandlers>
|
</issueHandlers>
|
||||||
</psalm>
|
</psalm>
|
||||||
@@ -25,7 +25,14 @@ class Hook_Formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @template Callback as string|object|array
|
||||||
|
* @template AcceptedArgs as int
|
||||||
|
* @template Hook as array{function: Callback, accepted_args: AcceptedArgs}
|
||||||
|
* @template Priority as array-key
|
||||||
|
* @template Hooks as array<Priority, array<Hook>>
|
||||||
|
*
|
||||||
* @param \WP_Hook|array $hook Hook instance.
|
* @param \WP_Hook|array $hook Hook instance.
|
||||||
|
* @psalm-param \WP_Hook|Hooks $hook
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -34,6 +41,7 @@ class Hook_Formatter {
|
|||||||
$callbacks = [];
|
$callbacks = [];
|
||||||
|
|
||||||
if ( $hook instanceof \WP_Hook ) {
|
if ( $hook instanceof \WP_Hook ) {
|
||||||
|
/** @psalm-var Hooks $hook->callbacks */
|
||||||
$hook = $hook->callbacks;
|
$hook = $hook->callbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,9 +51,12 @@ class Hook_Formatter {
|
|||||||
|
|
||||||
ksort( $hook );
|
ksort( $hook );
|
||||||
|
|
||||||
|
/** @psalm-suppress InvalidArgument */
|
||||||
$functions = array_merge( ...$hook );
|
$functions = array_merge( ...$hook );
|
||||||
|
|
||||||
|
/** @psalm-var Hook[] $functions */
|
||||||
foreach ( $functions as $function ) {
|
foreach ( $functions as $function ) {
|
||||||
|
/** @psalm-var Hook $function */
|
||||||
$callback = $this->get_callback_name( $function['function'], $function['accepted_args'] );
|
$callback = $this->get_callback_name( $function['function'], $function['accepted_args'] );
|
||||||
|
|
||||||
if ( false !== strpos( $callback, 'Hook_Collector' ) ) {
|
if ( false !== strpos( $callback, 'Hook_Collector' ) ) {
|
||||||
@@ -61,27 +72,27 @@ class Hook_Formatter {
|
|||||||
/**
|
/**
|
||||||
* @param string|object|array $callback Hook callback.
|
* @param string|object|array $callback Hook callback.
|
||||||
* @param int $args Number of accepted arguments.
|
* @param int $args Number of accepted arguments.
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
*/
|
||||||
protected function get_callback_name( $callback, int $args ): string {
|
protected function get_callback_name( $callback, int $args ): string {
|
||||||
|
|
||||||
switch ( gettype( $callback ) ) {
|
switch ( gettype( $callback ) ) {
|
||||||
case 'object':
|
case 'object':
|
||||||
$callback = $this->get_class_name( $callback );
|
$name = $this->get_class_name( $callback );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'array':
|
case 'array':
|
||||||
$class = is_string( $callback[0] )
|
/** @psalm-var array{0: object|string, 1: string} $callback */
|
||||||
|
$class = is_string( $callback[0] )
|
||||||
? $callback[0] . '::'
|
? $callback[0] . '::'
|
||||||
: $this->get_class_name( $callback[0] ) . '->';
|
: $this->get_class_name( $callback[0] ) . '->';
|
||||||
$callback = $class . $callback[1];
|
$name = $class . $callback[1];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$name = $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
$callback .= ( 1 === $args ) ? '' : "({$args})";
|
return $name . ( ( 1 === $args ) ? '' : "({$args})" );
|
||||||
|
|
||||||
return $callback;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,7 +102,7 @@ class Hook_Formatter {
|
|||||||
*/
|
*/
|
||||||
protected function get_class_name( $object ): string {
|
protected function get_class_name( $object ): string {
|
||||||
|
|
||||||
if ( is_a( $object, 'CLosure' ) ) {
|
if ( $object instanceof \Closure ) {
|
||||||
$class = new \ReflectionFunction( $object );
|
$class = new \ReflectionFunction( $object );
|
||||||
|
|
||||||
return 'closure from ' . $this->shorten_path( $class->getFileName() ) . ':' . $class->getStartLine();
|
return 'closure from ' . $this->shorten_path( $class->getFileName() ) . ':' . $class->getStartLine();
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ class Load_Order_Manager {
|
|||||||
* Reorder active plugins so Laps is first and starts timing load early.
|
* Reorder active plugins so Laps is first and starts timing load early.
|
||||||
*
|
*
|
||||||
* @param array $plugins Filtered array of active plugins’ basenames.
|
* @param array $plugins Filtered array of active plugins’ basenames.
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function pre_update_option_active_plugins( array $plugins ): array {
|
public function pre_update_option_active_plugins( array $plugins ): array {
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class Plugin extends Container {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $values Configuration values to apply.
|
* @param array $values Configuration values to apply.
|
||||||
|
* @psalm-param array<string, mixed> $values
|
||||||
*
|
*
|
||||||
* @psalm-suppress MixedArgument
|
* @psalm-suppress MixedArgument
|
||||||
* @psalm-suppress MixedAssignment
|
* @psalm-suppress MixedAssignment
|
||||||
|
|||||||
@@ -42,7 +42,14 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
|
|||||||
return new Lazy_Proxy_Collector( $laps['collectors'] );
|
return new Lazy_Proxy_Collector( $laps['collectors'] );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @psalm-suppress MixedInferredReturnType
|
||||||
|
*/
|
||||||
$pimple['records'] = function ( Plugin $laps ): array {
|
$pimple['records'] = function ( Plugin $laps ): array {
|
||||||
|
/**
|
||||||
|
* @psalm-suppress MixedMethodCall
|
||||||
|
* @psalm-suppress MixedReturnStatement
|
||||||
|
*/
|
||||||
return $laps['records.lazy']->get_records();
|
return $laps['records.lazy']->get_records();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,19 @@ class Hook_Collector extends Stopwatch_Collector {
|
|||||||
/** @var array $events */
|
/** @var array $events */
|
||||||
protected $events = [];
|
protected $events = [];
|
||||||
|
|
||||||
/** @var array */
|
/**
|
||||||
|
* @var array $callbacks
|
||||||
|
* @psalm-var array<string, \WP_Hook> $callbacks
|
||||||
|
*/
|
||||||
protected $callbacks = [];
|
protected $callbacks = [];
|
||||||
|
|
||||||
/** @var Hook_Formatter */
|
/** @var Hook_Formatter */
|
||||||
protected $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 = [];
|
private $calls = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,7 +61,7 @@ class Hook_Collector extends Stopwatch_Collector {
|
|||||||
/**
|
/**
|
||||||
* Time the point between network/MU plugins and regular if network activated.
|
* 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->stop( 'Network & MU Plugins Load' );
|
||||||
$this->start( 'Plugins Load', 'plugin' );
|
$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 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 $start_priority Start hook priority (defaults to -1).
|
||||||
* @param int $stop_priority Stop hook priority (defaults to max int).
|
* @param int $stop_priority Stop hook priority (defaults to max int).
|
||||||
|
*
|
||||||
|
* @psalm-suppress MissingClosureReturnType
|
||||||
|
* @psalm-suppress MissingClosureParamType
|
||||||
*/
|
*/
|
||||||
private function add_event(
|
private function add_event(
|
||||||
string $event,
|
string $event,
|
||||||
@@ -116,11 +125,13 @@ class Hook_Collector extends Stopwatch_Collector {
|
|||||||
$event .= $this->get_count_suffix( $event, true );
|
$event .= $this->get_count_suffix( $event, true );
|
||||||
|
|
||||||
if ( 'Sidebar' === $event ) {
|
if ( 'Sidebar' === $event ) {
|
||||||
|
/** @var string $input */
|
||||||
$event = $input;
|
$event = $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $start === $stop ) {
|
if ( $start === $stop ) {
|
||||||
global $wp_filter;
|
global $wp_filter;
|
||||||
|
/** @psalm-var array<string, \WP_Hook> $wp_filter */
|
||||||
$this->callbacks[ $event ] = $wp_filter[ $start ];
|
$this->callbacks[ $event ] = $wp_filter[ $start ];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +147,7 @@ class Hook_Collector extends Stopwatch_Collector {
|
|||||||
$event .= $this->get_count_suffix( $event );
|
$event .= $this->get_count_suffix( $event );
|
||||||
|
|
||||||
if ( 'Sidebar' === $event ) {
|
if ( 'Sidebar' === $event ) {
|
||||||
|
/** @var string $input */
|
||||||
$event = $input;
|
$event = $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ class Http_Collector extends Stopwatch_Collector {
|
|||||||
/** @var Backtrace_Formatter */
|
/** @var Backtrace_Formatter */
|
||||||
private $formatter;
|
private $formatter;
|
||||||
|
|
||||||
/** @var array */
|
/**
|
||||||
|
* @var array $callers
|
||||||
|
* @psalm-var array<string, string> $callers
|
||||||
|
*/
|
||||||
private $callers = [];
|
private $callers = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +42,7 @@ class Http_Collector extends Stopwatch_Collector {
|
|||||||
* @param array $args HTTP request arguments.
|
* @param array $args HTTP request arguments.
|
||||||
* @param string $url The request URL.
|
* @param string $url The request URL.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return false|array|\WP_Error
|
||||||
*/
|
*/
|
||||||
public function pre_http_request( $false, array $args, string $url ) {
|
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.
|
* Converts recorded information into a Record instance.
|
||||||
*
|
*
|
||||||
* @param array $entry Data entry for the plugin.
|
* @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(
|
return new Record(
|
||||||
plugin_basename( $entry['name'] ),
|
plugin_basename( $entry['name'] ),
|
||||||
$entry['origin'],
|
$entry['origin'],
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ use Rarst\Laps\Record\Record;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes SQL events from data logged by wpdb.
|
* 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 {
|
class Sql_Collector implements Record_Collector_Interface {
|
||||||
|
|
||||||
@@ -59,11 +61,13 @@ class Sql_Collector implements Record_Collector_Interface {
|
|||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
/** @psalm-suppress MixedPropertyFetch */
|
||||||
if ( empty( $wpdb->queries ) ) {
|
if ( empty( $wpdb->queries ) ) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var array $wpdb->queries */
|
/** @var array $wpdb->queries */
|
||||||
|
/** @psalm-var array<int, QueryData> $wpdb->queries */
|
||||||
$records = array_filter( array_map( [ $this, 'transform' ], array_keys( $wpdb->queries ), $wpdb->queries ) );
|
$records = array_filter( array_map( [ $this, 'transform' ], array_keys( $wpdb->queries ), $wpdb->queries ) );
|
||||||
|
|
||||||
return $records;
|
return $records;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class Stopwatch_Collector implements Record_Collector_Interface {
|
|||||||
*/
|
*/
|
||||||
public function get_records(): array {
|
public function get_records(): array {
|
||||||
|
|
||||||
|
/** @psalm-var array<string, StopwatchEvent> $events */
|
||||||
$events = $this->stopwatch->getSectionEvents( '__root__' );
|
$events = $this->stopwatch->getSectionEvents( '__root__' );
|
||||||
|
|
||||||
/** @var string $name */
|
/** @var string $name */
|
||||||
|
|||||||
Reference in new issue
Block a user