Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions classes/Collector_Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ public function process() {
}

/**
* Undocumented function
*
* @return array<string, array>|null
* @phpstan-return array<string, array{
* id: string,
Expand All @@ -275,11 +273,6 @@ protected static function get_script_modules(): ?array {
}

$modules = wp_script_modules();

if ( ! ( $modules instanceof \WP_Script_Modules ) ) {
return null;
}

$reflector = new ReflectionClass( $modules );

$get_marked_for_enqueue = $reflector->getMethod( 'get_marked_for_enqueue' );
Expand Down
39 changes: 3 additions & 36 deletions collectors/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'E_RECOVERABLE_ERROR' => 4096,
'E_DEPRECATED' => 8192,
'E_USER_DEPRECATED' => 16384,
'E_ALL' => 30719,
'E_ALL' => E_ALL,
);

$levels = array_fill_keys( array_keys( $constants ), false );
Expand Down Expand Up @@ -84,23 +84,14 @@
'key_buffer_size' => true, # Key cache size limit
'max_allowed_packet' => false, # Individual query size limit
'max_connections' => false, # Max number of client connections
'query_cache_limit' => true, # Individual query cache size limit
'query_cache_size' => true, # Total cache size limit
'query_cache_type' => 'ON', # Query cache on or off
'innodb_buffer_pool_size' => false, # The amount of memory allocated to the InnoDB buffer pool
);

/** @var QM_Collector_DB_Queries|null */
$dbq = QM_Collectors::get( 'db_queries' );

if ( $dbq ) {
if ( method_exists( $dbq->wpdb, 'db_version' ) ) {
$server = $dbq->wpdb->db_version();
// query_cache_* deprecated since MySQL 5.7.20
if ( version_compare( $server, '5.7.20', '>=' ) ) {
unset( $mysql_vars['query_cache_limit'], $mysql_vars['query_cache_size'], $mysql_vars['query_cache_type'] );
}
}
$server = $dbq->wpdb->db_version();

// phpcs:disable
/** @var array<int, stdClass>|null */
Expand Down Expand Up @@ -131,10 +122,8 @@
$client_version = null;
}

$server_version = self::get_server_version( $dbq->wpdb );

$info = array(
'server-version' => $server_version,
'server-version' => $dbq->wpdb->db_server_info(),
'extension' => $extension,
'client-version' => $client_version,
'user' => $dbq->wpdb->dbuser,
Expand All @@ -142,7 +131,7 @@
'database' => $dbq->wpdb->dbname,
);

$this->data->db = array(

Check failure on line 134 in collectors/environment.php

View workflow job for this annotation

GitHub Actions / PHP / PHPStan on PHP 7.4

Property QM_Data_Environment::$db (array{info: array{server-version: string, extension: string|null, client-version: string|null, user: string, host: string, database: string}, vars: array<string, bool|string>, variables: list<stdClass>}) does not accept array{info: array{server-version: string, extension: class-string<mysqli>|null, client-version: non-falsy-string|null, user: string, host: string, database: string}, vars: array{key_buffer_size: true, max_allowed_packet: false, max_connections: false, innodb_buffer_pool_size: false}, variables: array<int, stdClass>}.

Check failure on line 134 in collectors/environment.php

View workflow job for this annotation

GitHub Actions / PHP / PHPStan on PHP 8.3

Property QM_Data_Environment::$db (array{info: array{server-version: string, extension: string|null, client-version: string|null, user: string, host: string, database: string}, vars: array<string, bool|string>, variables: list<stdClass>}) does not accept array{info: array{server-version: string, extension: class-string<mysqli>|null, client-version: non-falsy-string|null, user: string, host: string, database: string}, vars: array{key_buffer_size: true, max_allowed_packet: false, max_connections: false, innodb_buffer_pool_size: false}, variables: array<int, stdClass>}.
'info' => $info,
'vars' => $mysql_vars,
'variables' => is_array( $variables ) ? $variables : array(),
Expand Down Expand Up @@ -262,28 +251,6 @@
return $version;
}

/**
* @param wpdb $db
* @return string
*/
protected static function get_server_version( wpdb $db ) {
$version = null;

if ( method_exists( $db, 'db_server_info' ) ) {
$version = $db->db_server_info();
}

if ( ! $version ) {
$version = $db->get_var( 'SELECT VERSION()' );
}

if ( ! $version ) {
$version = __( 'Unknown', 'query-monitor' );
}

return $version;
}

/**
* @return string
*/
Expand Down
8 changes: 4 additions & 4 deletions collectors/php_errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co
$type = 'deprecated';
break;

}
// E_STRICT is deprecated in PHP 8.4 so we'll use its numeric value directly.
case 2048: // E_STRICT
$type = 'strict';
break;

// E_STRICT is deprecated in PHP 8.4 so it needs to be behind a version check.
if ( null === $type && version_compare( PHP_VERSION, '8.4', '<' ) && E_STRICT === $errno ) {
$type = 'strict';
}

if ( null === $type ) {
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
"codeception/util-universalframework": "^1.0",
"dealerdirect/phpcodesniffer-composer-installer": "0.7.2",
"johnbillion/plugin-infrastructure": "dev-trunk",
"johnbillion/wp-compat": "0.3.1",
"johnbillion/wp-compat": "1.3.0",
"lucatume/wp-browser": "3.2.3",
"phpcompatibility/phpcompatibility-wp": "2.1.5",
"phpstan/phpstan": "1.12.11",
"phpstan/phpstan-deprecation-rules": "1.2.1",
"phpstan/phpstan-phpunit": "1.4.1",
"phpstan/phpstan": "2.1.17",
"phpstan/phpstan-deprecation-rules": "2.0.3",
"phpstan/phpstan-phpunit": "2.0.6",
"roots/wordpress-core-installer": "1.100.0",
"roots/wordpress-full": "*",
"squizlabs/php_codesniffer": "3.11.1",
"szepeviktor/phpstan-wordpress": "1.3.5",
"szepeviktor/phpstan-wordpress": "2.0.2",
"wp-coding-standards/wpcs": "2.3.0"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions output/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
continue;
}

QM_Output_Html_Hooks::output_hook_table( $this->collector->$key, true );

Check failure on line 189 in output/Html.php

View workflow job for this annotation

GitHub Actions / PHP / PHPStan on PHP 7.4

Parameter #1 $hooks of static method QM_Output_Html_Hooks::output_hook_table() expects array<int, array<mixed>>, array<string, array<string, mixed>> given.

Check failure on line 189 in output/Html.php

View workflow job for this annotation

GitHub Actions / PHP / PHPStan on PHP 8.3

Parameter #1 $hooks of static method QM_Output_Html_Hooks::output_hook_table() expects array<int, array<mixed>>, array<string, array<string, mixed>> given.
}

echo '</tbody>';
Expand Down Expand Up @@ -298,11 +298,11 @@
* @return string Markup for the table filter controls.
*/
protected function build_filter( $name, $values, $label, $args = array() ) {

if ( empty( $values ) || ! is_array( $values ) ) {
if ( empty( $values ) ) {
return esc_html( $label ); // Return label text, without being marked up as a label element.
}

// @phpstan-ignore function.alreadyNarrowedType (some plugins may still pass a string here for highlighting)
if ( ! is_array( $args ) ) {
$args = array(
'highlight' => $args,
Expand Down
18 changes: 4 additions & 14 deletions output/html/php_errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,10 @@ public function output() {
$row_attr['data-qm-type'] = ucfirst( $type );
$row_attr['data-qm-key'] = $error_key;
$row_attr['data-qm-count'] = $error['calls'];
$row_attr['data-qm-component'] = $error['component']->name;

if ( $error['component'] ) {
$component = $error['component'];
$row_attr['data-qm-component'] = $component->name;

if ( 'core' !== $component->context ) {
$row_attr['data-qm-component'] .= ' non-core';
}
if ( 'core' !== $error['component']->context ) {
$row_attr['data-qm-component'] .= ' non-core';
}

$attr = '';
Expand Down Expand Up @@ -163,13 +159,7 @@ public function output() {

echo '</ol></td>';
echo '<td class="qm-num">' . esc_html( number_format_i18n( $error['calls'] ) ) . '</td>';

if ( ! empty( $component ) ) {
echo '<td class="qm-nowrap">' . esc_html( $component->name ) . '</td>';
} else {
echo '<td><em>' . esc_html__( 'Unknown', 'query-monitor' ) . '</em></td>';
}

echo '<td class="qm-nowrap">' . esc_html( $error['component']->name ) . '</td>';
echo '</tr>';
}
}
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ parameters:
# Passing ints and floats to these functions is fine
- '#^Parameter \#1 \$text of function (esc_html|esc_attr) expects string, int\|string given#'
- '#^Parameter \#1 \$text of function (esc_html|esc_attr) expects string, float\|int\|string given#'
# ...
-
identifier: phpstanWP.wpConstant.fetch
# ...
-
path: collectors/languages.php
identifier: WPCompat.filterNotAvailable.loadtranslationfile
2 changes: 2 additions & 0 deletions tests/integration/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function go_to_with_template( string $url ) {
$this->go_to( $url );

ob_start();

// @phpstan-ignore require.fileNotFound
require ABSPATH . WPINC . '/template-loader.php';
return (string) ob_get_clean();
}
Expand Down
Loading