Added psalm configuration and refined source.

This commit is contained in:
Andrey Savchenko committed 2018-11-30 18:15:38 +02:00
1 parent 4013046e4f
commit 70de78b276
13 files changed
+81 -3

No files matched your search

+3
View File
@@ -54,5 +54,8 @@
"js/tests"
]
}
},
"scripts": {
"psalm": "psalm --config=config/psalm.xml"
}
}
+32
View File
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
<directory name="src/mustache/cache"/>
</ignoreFiles>
</projectFiles>
<issueHandlers>
<LessSpecificReturnType errorLevel="info"/>
<UndefinedFunction errorLevel="suppress"/>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="WP_Admin_Bar"/>
<referencedClass name="WP_Error"/>
<referencedClass name="WP_Hook"/>
</errorLevel>
</UndefinedClass>
<MixedArgument>
<errorLevel type="suppress">
<file name="src/Provider/Record_Provider.php" />
</errorLevel>
</MixedArgument>
</issueHandlers>
</psalm>
+3
View File
@@ -21,6 +21,7 @@ class Hybrid_Events implements Hook_Event_Config_Interface {
return $events;
}
/** @var string $prefix */
$prefix = hybrid_get_prefix();
$events["{$prefix}_before_header"][10] = [
@@ -34,9 +35,11 @@ class Hybrid_Events implements Hook_Event_Config_Interface {
'category' => 'theme',
];
/** @var array $sidebars */
$sidebars = get_theme_support( 'hybrid-core-sidebars' );
if ( ! empty( $sidebars[0] ) ) {
/** @var string $sidebar */
foreach ( $sidebars[0] as $sidebar ) {
$events["{$prefix}_before_{$sidebar}"][10] = [
+5 -1
View File
@@ -8,7 +8,7 @@ namespace Rarst\Laps\Formatter;
*/
class Backtrace_Formatter {
/** @var array $skip String matches to omit. */
/** @var string[] $skip String matches to omit. */
protected static $skip = [
'wp-blog-header.php',
'wp-load.php',
@@ -74,9 +74,13 @@ class Backtrace_Formatter {
}
/**
*
* @param string $item Backtrace item.
*
* @return string
*
* @psalm-suppress PossiblyFalseOperand
* @psalm-suppress MixedInferredReturnType
*/
protected function shorten_include( string $item ): string {
+2
View File
@@ -29,6 +29,8 @@ class Toolbar_Manager {
* Render interface and add to the toolbar.
*
* @param \WP_Admin_Bar $wp_admin_bar WordPress core toolbar object.
*
* @psalm-suppress MixedArgument
*/
public function admin_bar_menu( \WP_Admin_Bar $wp_admin_bar ): void {
+2
View File
@@ -15,6 +15,8 @@ class Mustache_Cache_FrozenCache extends \Mustache_Cache_FilesystemCache {
* @param string $value Value.
*
* @return void
*
* @psalm-suppress InvalidScalarArgument
*/
public function cache( $key, $value ): void {
+5
View File
@@ -20,6 +20,9 @@ class Plugin extends Container {
/**
* @param array $values Configuration values to apply.
*
* @psalm-suppress MixedArgument
* @psalm-suppress MixedAssignment
*/
public function __construct( array $values = [] ) {
@@ -60,6 +63,8 @@ class Plugin extends Container {
/**
* Start Stopwatch and timing plugin load immediately, then set up core events and needed hooks.
*
* @psalm-suppress MixedAssignment
*/
public function run(): void {
+4
View File
@@ -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.
+12 -1
View File
@@ -19,7 +19,7 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
/**
* @param Stopwatch $stopwatch Stopwatch instance.
* @param array $event_configs Starts and stops configuration.
* @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.
+1 -1
View File
@@ -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 = [];
/**
+6
View File
@@ -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
View File
@@ -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 );
}