Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON schemas for data objects #756

Merged
merged 85 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
506f2d7
Introduce JSON schema definitions for the DTOs.
johnbillion Apr 13, 2023
cdab99b
Start using the TypeScript definitions for data.
johnbillion Apr 14, 2023
acac422
None of these are nullable.
johnbillion Apr 15, 2023
c2c28b0
Add a schema for assets.
johnbillion Apr 15, 2023
b44e336
Add a schema for the cache.
johnbillion Apr 15, 2023
17e25c7
Update the banner comment.
johnbillion Apr 16, 2023
441564b
Make more use of recursive calls for type resolution.
johnbillion Apr 16, 2023
4463c76
Add a schema for user capability checks.
johnbillion Apr 16, 2023
997a80e
Add a schema for conditionals.
johnbillion Apr 16, 2023
359020d
Add a schema for database query callers.
johnbillion Apr 16, 2023
d328682
Add a schema for database query components.
johnbillion Apr 16, 2023
6d3c2bb
Add a schema for duplicate database queries.
johnbillion Apr 16, 2023
f767ff6
Add a schema for database queries.
johnbillion Apr 16, 2023
99cc8b8
I'll come back to this.
johnbillion Apr 19, 2023
6382d32
Fix the multiple type listings.
johnbillion Apr 19, 2023
113a4ac
Implement the indentation.
johnbillion Apr 19, 2023
2864709
Add a schema for the environment.
johnbillion Apr 19, 2023
7a056e5
More adjustments.
johnbillion Apr 19, 2023
db97b30
Update the Environment panel.
johnbillion Apr 19, 2023
28064a5
More updates to the Environment panel.
johnbillion Apr 19, 2023
e71078a
Add a missing field.
johnbillion Apr 19, 2023
faff431
Add a schema for hooks.
johnbillion Apr 19, 2023
6c27232
This doesn't have additional properties.
johnbillion Apr 19, 2023
9ab2f31
Add a schema for HTTP API requests.
johnbillion Apr 19, 2023
1208d08
Improve the int/float handling.
johnbillion Apr 20, 2023
71f1a11
Improve this header.
johnbillion Apr 20, 2023
ae58ecd
Support for enums.
johnbillion Apr 20, 2023
2f19346
Add a schema for languages.
johnbillion Apr 20, 2023
01507d3
Add a schema for the logger.
johnbillion Apr 22, 2023
8a54092
Add a schema for Multisite.
johnbillion Apr 22, 2023
f7331bb
Add a schema for the overview.
johnbillion Apr 22, 2023
110c4c3
Add a schema for PHP errors.
johnbillion Apr 22, 2023
dd2748f
Add a schema for the raw request and response.
johnbillion Apr 22, 2023
4d981da
Add a schema for a redirect.
johnbillion Apr 22, 2023
d9151dc
Add a schema for the request.
johnbillion Apr 22, 2023
c837589
Support properties with no type declared.
johnbillion Apr 22, 2023
95829d0
Support anyOf and oneOf.
johnbillion Apr 22, 2023
a4c43b1
Add a schema for timing data.
johnbillion Apr 22, 2023
2875e7d
Add a schema for transients.
johnbillion Apr 22, 2023
dc69e93
Update wp-json-schemas and wp-types.
johnbillion Apr 23, 2023
508a0ed
Add a schema for theme data.
johnbillion Apr 23, 2023
0e5a1ae
Add the database queries definition to the schema.
johnbillion Apr 23, 2023
dd6ca95
More implementation into the panels.
johnbillion Apr 23, 2023
84b14ba
Better data for the request.
johnbillion Apr 23, 2023
30ec1ff
More implementation into the panels.
johnbillion Apr 23, 2023
90e1623
Move the data schemas into a subdirectory.
johnbillion Apr 23, 2023
84fdedd
Add a schema for `QM_Component`.
johnbillion Apr 23, 2023
8590b5f
Tidying up.
johnbillion Apr 23, 2023
f955c9b
Split this up a bit.
johnbillion Apr 23, 2023
cd59f24
Only parse JSON files.
johnbillion Apr 23, 2023
3e78b37
Add a schema for stack trace frames.
johnbillion Apr 23, 2023
9a49429
Build the schemas when building the build.
johnbillion Apr 23, 2023
19c891c
Oops.
johnbillion Apr 23, 2023
0e9cc1d
More schemas for stack trace data.
johnbillion Apr 23, 2023
f4a4a49
More structure for timing data.
johnbillion Apr 23, 2023
d5226e3
Fixing up the request data.
johnbillion Apr 23, 2023
212d7fa
Add support for definition reference resolution.
johnbillion Apr 24, 2023
360f380
More structure for PHP error data.
johnbillion Apr 24, 2023
1b9b551
This is a frame item.
johnbillion Apr 24, 2023
50d1ca6
These custom notations should take preference.
johnbillion Apr 24, 2023
cae57c7
Merge branch 'client-side-rendering' into json-schemas
johnbillion May 1, 2023
65266e3
This is no longer present.
johnbillion May 1, 2023
889159b
Move everything in the schema up a level and add the abstract data cl…
johnbillion May 1, 2023
85a2c03
Get more specific with the shape of database query data.
johnbillion May 1, 2023
03b0a6d
Merge branch 'client-side-rendering' into json-schemas
johnbillion Sep 25, 2023
ce07082
This is a return tag.
johnbillion Sep 25, 2023
76b17d7
Add a schema for the Doing it Wrong data.
johnbillion Sep 25, 2023
77ca171
Update schemas with recent changes in the develop branch.
johnbillion Sep 25, 2023
ab6a26a
Everything is legacy.
johnbillion Oct 8, 2023
39f7c9f
Fix the type for the missing dependencies list.
johnbillion Oct 8, 2023
04cb398
Be more strict about these inline type declarations.
johnbillion Oct 8, 2023
2ba4da0
This has a known shape now.
johnbillion Oct 8, 2023
b5a1d84
Document the globals.
johnbillion Oct 8, 2023
6b44575
Fix the multisite data structure.
johnbillion Oct 8, 2023
6a965e8
Reference the source schema in generated DTOs.
johnbillion Oct 8, 2023
6013937
Partially update the database queries data schema.
johnbillion Oct 8, 2023
5b6077c
Build the schemas during the tests.
johnbillion Oct 12, 2023
e8589f7
These elements are optional.
johnbillion Oct 12, 2023
e0a956f
Replace the manual class comments with more schema definitions.
johnbillion Oct 14, 2023
0ba683f
Move this into a type for clarity.
johnbillion Oct 14, 2023
8055ee7
Fix up some more definitions for query data.
johnbillion Oct 17, 2023
b2633f3
Remove unnecessary manual typing.
johnbillion Oct 17, 2023
f758281
This property may not exist.
johnbillion Oct 17, 2023
b4b6f46
This property may not exist.
johnbillion Oct 17, 2023
36b814f
Fix up the queried object data.
johnbillion Oct 17, 2023
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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
engine-strict=true
legacy-peer-deps=true
1 change: 1 addition & 0 deletions classes/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ final public function set_id( $id ) {
* @return void
*/
final public function process_concerns() {
/** @var array<string, WP_Hook> $wp_filter */
global $wp_filter;

$tracked = array();
Expand Down
4 changes: 2 additions & 2 deletions classes/Collector_Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function process() {
sort( $all_dependents );
$this->data->dependents = $all_dependents;

$this->data->missing_dependencies = array_unique( $missing_dependencies );
$this->data->missing_dependencies = $missing_dependencies;
}

/**
Expand Down Expand Up @@ -295,7 +295,7 @@ public function get_dependents( _WP_Dependency $dependency, WP_Dependencies $dep
* }
*/
public function get_dependency_data( _WP_Dependency $dependency ) {
/** @var QM_Data_Assets */
/** @var QM_Data_Assets $data */
$data = $this->get_data();
$loader = rtrim( $this->get_dependency_type(), 's' );
$src = $dependency->src;
Expand Down
2 changes: 2 additions & 0 deletions classes/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public static function verify_cookie( $value ) {
* @return bool True on success, false on failure.
*/
public static function switch_to_locale( $locale ) {
/** @var ?WP_Locale_Switcher $wp_locale_switcher */
global $wp_locale_switcher;

if ( function_exists( 'switch_to_locale' ) && ( $wp_locale_switcher instanceof WP_Locale_Switcher ) ) {
Expand All @@ -227,6 +228,7 @@ public static function switch_to_locale( $locale ) {
* @return string|false Locale on success, false on error.
*/
public static function restore_previous_locale() {
/** @var ?WP_Locale_Switcher $wp_locale_switcher */
global $wp_locale_switcher;

if ( function_exists( 'restore_previous_locale' ) && ( $wp_locale_switcher instanceof WP_Locale_Switcher ) ) {
Expand Down
9 changes: 8 additions & 1 deletion classes/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ class QM_Hook {
* type: 'action'|'filter',
* actions: list<array{
* priority: int,
* callback: array<string, mixed>,
* callback: array{
* accepted_args: int,
* name?: string,
* file?: string|false,
* line?: int|false,
* error?: WP_Error,
* component?: QM_Component,
* },
* }>,
* parts: list<string>,
* components: array<string, string>,
Expand Down
2 changes: 1 addition & 1 deletion classes/QM.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static function debug( $message, array $context = array() ) {
* @return void
*/
public static function log( $level, $message, array $context = array() ) {
/** @var QM_Collector_Logger */
/** @var QM_Collector_Logger $logger */
$logger = QM_Collectors::get( 'logger' );
$logger->log( $level, $message, $context );
}
Expand Down
9 changes: 8 additions & 1 deletion classes/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ public function lap( array $data = null, $name = null ) {
}

/**
* @return mixed[]
* @return array<string, array<string, mixed>>
* @phpstan-return array<string, array{
* time: float,
* time_used: float,
* memory: int,
* memory_used: int,
* data: mixed[]|null,
* }>
*/
public function get_laps() {

Expand Down
5 changes: 3 additions & 2 deletions classes/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@
* @param array<string, mixed> $callback
* @return array<string, mixed>
* @phpstan-return array{
* accepted_args: int,
* name?: string,
* file?: string|false,
* line?: string|false,
* line?: int|false,
* error?: WP_Error,
* component?: QM_Component,
* }
Expand Down Expand Up @@ -396,7 +397,7 @@
if ( '__lambda_func' === $name || 0 === strpos( $name, 'lambda_' ) ) {
if ( $callback['file'] && preg_match( '|(?P<file>.*)\((?P<line>[0-9]+)\)|', $callback['file'], $matches ) ) {
$callback['file'] = $matches['file'];
$callback['line'] = $matches['line'];
$callback['line'] = (int) $matches['line'];
$file = trim( self::standard_dir( $callback['file'], '' ), '/' );
/* translators: 1: Line number, 2: File name */
$callback['name'] = sprintf( __( 'Anonymous function on line %1$d of %2$s', 'query-monitor' ), $callback['line'], $file );
Expand Down Expand Up @@ -424,7 +425,7 @@

unset( $callback['function'], $callback['class'] );

return $callback;

Check failure on line 428 in classes/Util.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.0 / PHP / PHP 8.0

Method QM_Util::populate_callback() should return array{accepted_args: int, name?: string, file?: string|false, line?: int|false, error?: WP_Error, component?: QM_Component} but returns array<string, mixed>.

Check failure on line 428 in classes/Util.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 7.4 / PHP / PHP 7.4

Method QM_Util::populate_callback() should return array{accepted_args: int, name?: string, file?: string|false, line?: int|false, error?: WP_Error, component?: QM_Component} but returns array<string, mixed>.

Check failure on line 428 in classes/Util.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.1 / PHP / PHP 8.1

Method QM_Util::populate_callback() should return array{accepted_args: int, name?: string, file?: string|false, line?: int|false, error?: WP_Error, component?: QM_Component} but returns array<string, mixed>.

Check failure on line 428 in classes/Util.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.2 / PHP / PHP 8.2

Method QM_Util::populate_callback() should return array{accepted_args: int, name?: string, file?: string|false, line?: int|false, error?: WP_Error, component?: QM_Component} but returns array<string, mixed>.

}

Expand Down
7 changes: 4 additions & 3 deletions collectors/block_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function filter_render_block( $block_content, array $block ) {
}

public function process() {
/** @var ?string $_wp_current_template_content */
global $_wp_current_template_content;

$this->data->block_editor_enabled = self::wp_block_editor_enabled();
Expand Down Expand Up @@ -228,7 +229,7 @@ protected static function wp_has_blocks( $content ) {

/**
* @param string $content
* @return array<int, mixed>|null
* @return array<int, mixed>
*/
protected static function wp_parse_blocks( $content ) {
if ( function_exists( 'parse_blocks' ) ) {
Expand All @@ -237,11 +238,11 @@ protected static function wp_parse_blocks( $content ) {
return gutenberg_parse_blocks( $content );
}

return null;
return array();
}

/**
* @return array<int, string>|null
* @return array<int, string>
*/
protected static function wp_get_dynamic_block_names() {
if ( function_exists( 'get_dynamic_block_names' ) ) {
Expand Down
1 change: 1 addition & 0 deletions collectors/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function get_storage(): QM_Data {
* @return void
*/
public function process() {
/** @var ?object $wp_object_cache */
global $wp_object_cache;

$this->data->has_object_cache = (bool) wp_using_ext_object_cache();
Expand Down
4 changes: 1 addition & 3 deletions collectors/db_dupes.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function process() {
foreach ( $query_ids as $query_id ) {

if ( isset( $dbq_data->rows[ $query_id ]['trace'] ) ) {
/** @var QM_Backtrace */
$trace = $dbq_data->rows[ $query_id ]['trace'];
$stack = array_column( $trace->get_filtered_trace(), 'id' );
$component = $trace->get_component();
Expand All @@ -68,8 +67,7 @@ public function process() {
$components[ $sql ][ $component->name ] = 1;
}
} else {
/** @var array<int, string> */
$stack = $dbq_data->rows[ $query_id ]['stack'];
$stack = $dbq_data->rows[ $query_id ]['stack'] ?? array();
}

// Populate the caller counts for this query
Expand Down
31 changes: 18 additions & 13 deletions collectors/db_queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
}

/**
* @phpstan-type QueryStandard array{
* 0: string,
* 1: float,
* 2: string,
* trace?: QM_Backtrace,
* result?: int|bool|WP_Error,
* }
* @phpstan-type QueryVIP array{
* query: string,
* elapsed: float,
* debug: string,
* }
*
* @extends QM_DataCollector<QM_Data_DB_Queries>
*/
class QM_Collector_DB_Queries extends QM_DataCollector {
Expand Down Expand Up @@ -107,6 +120,10 @@
* @return void
*/
public function process_db_object() {
/**
* @var WP_Query $wp_the_query
* @var wpdb $wpdb
*/
global $wp_the_query, $wpdb;

$this->wpdb = $wpdb;
Expand All @@ -129,17 +146,7 @@
}

/**
* @phpstan-var array{
* 0: string,
* 1: float,
* 2: string,
* trace?: QM_Backtrace,
* result?: int|bool|WP_Error,
* }|array{
* query: string,
* elapsed: float,
* debug: string,
* } $query
* @phpstan-var QueryStandard|QueryVIP $query
*/
foreach ( $wpdb->queries as $query ) {
$callers = array();
Expand Down Expand Up @@ -179,7 +186,6 @@
$caller = $query['trace']->get_caller();
$caller_name = $caller['display'] ?? 'Unknown';
$caller = $caller['display'] ?? 'Unknown';
$filtered_trace = $query['trace']->get_filtered_trace();

} else {

Expand All @@ -190,7 +196,6 @@
$callers = QM_Backtrace::get_filtered_stack( $callers );
$caller = reset( $callers );
$caller_name = $caller;
$filtered_trace = null;

}

Expand Down Expand Up @@ -222,7 +227,7 @@
$this->data->expensive[] = $row;
}

$this->data->rows[ $i ] = $row;

Check failure on line 230 in collectors/db_queries.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.0 / PHP / PHP 8.0

Property QM_Data_DB_Queries::$rows (array<int, array{caller: string, caller_name: string|null, stack?: array<int, string>, sql: string, ltime: float, result: bool|int|WP_Error, type: string, component: QM_Component|null, ...}>) does not accept non-empty-array<int, array{caller: mixed, caller_name: mixed, stack?: array<int, string>, sql: string, ltime: float, result: bool|int|WP_Error|null, type: string, component: QM_Component|null, ...}>.

Check failure on line 230 in collectors/db_queries.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 7.4 / PHP / PHP 7.4

Property QM_Data_DB_Queries::$rows (array<int, array{caller: string, caller_name: string|null, stack?: array<int, string>, sql: string, ltime: float, result: bool|int|WP_Error, type: string, component: QM_Component|null, ...}>) does not accept non-empty-array<int, array{caller: mixed, caller_name: mixed, stack?: array<int, string>, sql: string, ltime: float, result: bool|int|WP_Error|null, type: string, component: QM_Component|null, ...}>.

Check failure on line 230 in collectors/db_queries.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.1 / PHP / PHP 8.1

Property QM_Data_DB_Queries::$rows (array<int, array{caller: string, caller_name: string|null, stack?: array<int, string>, sql: string, ltime: float, result: bool|int|WP_Error, type: string, component: QM_Component|null, ...}>) does not accept non-empty-array<int, array{caller: mixed, caller_name: mixed, stack?: array<int, string>, sql: string, ltime: float, result: bool|int|WP_Error|null, type: string, component: QM_Component|null, ...}>.

Check failure on line 230 in collectors/db_queries.php

View workflow job for this annotation

GitHub Actions / PHP / PHP 8.2 / PHP / PHP 8.2

Property QM_Data_DB_Queries::$rows (array<int, array{caller: string, caller_name: string|null, stack?: array<int, string>, sql: string, ltime: float, result: bool|int|WP_Error, type: string, component: QM_Component|null, ...}>) does not accept non-empty-array<int, array{caller: mixed, caller_name: mixed, stack?: array<int, string>, sql: string, ltime: float, result: bool|int|WP_Error|null, type: string, component: QM_Component|null, ...}>.
$i++;
}

Expand Down
2 changes: 1 addition & 1 deletion collectors/debug_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function render() {
* @return void
*/
function register_qm_collectors_debug_bar() {

/** @var ?Debug_Bar $debug_bar */
global $debug_bar;

if ( class_exists( 'Debug_Bar', false ) || qm_debug_bar_being_activated() ) {
Expand Down
7 changes: 3 additions & 4 deletions collectors/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected static function get_error_levels( $error_reporting ) {
* @return void
*/
public function process() {

/** @var string $wp_version */
global $wp_version;

$mysql_vars = array(
Expand All @@ -88,7 +88,7 @@ public function process() {
'innodb_buffer_pool_size' => false, # The amount of memory allocated to the InnoDB buffer pool
);

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

if ( $dbq ) {
Expand All @@ -101,7 +101,7 @@ public function process() {
}

// phpcs:disable
/** @var array<int, stdClass>|null */
/** @var array<int, stdClass>|null $variables */
$variables = $dbq->wpdb->get_results( "
SHOW VARIABLES
WHERE Variable_name IN ( '" . implode( "', '", array_keys( $mysql_vars ) ) . "' )
Expand Down Expand Up @@ -141,7 +141,6 @@ public function process() {

$this->data->db = array(
'info' => $info,
'vars' => $mysql_vars,
'variables' => $variables ?: array(),
);
}
Expand Down
6 changes: 3 additions & 3 deletions collectors/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class QM_Collector_HTTP extends QM_DataCollector {
* @phpstan-var array<string, array{
* end: float,
* args: array<string, mixed>,
* response: mixed[]|WP_Error,
* response: array<string, mixed>|WP_Error,
* info: array<string, mixed>|null,
* }>
*/
Expand Down Expand Up @@ -283,7 +283,7 @@ public function action_fsockopen_after_request( $headers, array $info = null ) {
* @return void
*/
public function log_http_response( $response, array $args, $url ) {
/** @var string */
/** @var string $key */
$key = $args['_qm_key'];

if ( is_array( $response ) && isset( $response['body'] ) ) {
Expand All @@ -299,7 +299,7 @@ public function log_http_response( $response, array $args, $url ) {
);

if ( isset( $args['_qm_original_key'] ) ) {
/** @var string */
/** @var string $original_key */
$original_key = $args['_qm_original_key'];
$this->http_responses[ $original_key ]['end'] = $this->http_requests[ $original_key ]['start'];
$this->http_responses[ $original_key ]['response'] = new WP_Error( 'http_request_not_executed', sprintf(
Expand Down
Loading
Loading