1 parent
cd55061e69
commit
204c1df755
29 files changed
+115
-75
No files matched your search
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -20,11 +21,11 @@ class Core_Load_Collector implements Record_Collector_Interface {
|
||||
/**
|
||||
* @return Record_Interface[]
|
||||
*/
|
||||
public function get_records() {
|
||||
public function get_records(): array {
|
||||
|
||||
global $timestart;
|
||||
|
||||
$request_time = $_SERVER['REQUEST_TIME_FLOAT'];
|
||||
$request_time = filter_var( $_SERVER['REQUEST_TIME_FLOAT'], FILTER_VALIDATE_FLOAT );
|
||||
|
||||
return [
|
||||
new Record( 'PHP Load', $request_time, $timestart - $request_time, '', 'php' ),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -37,7 +38,7 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
|
||||
*
|
||||
* @param array $stops Starts and stops to hook.
|
||||
*/
|
||||
public function add_events( $stops ) {
|
||||
public function add_events( array $stops ): void {
|
||||
|
||||
$this->events = array_merge( $this->events, $stops );
|
||||
|
||||
@@ -51,7 +52,7 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
|
||||
/**
|
||||
* When theme is done possibly add vendor-specific events.
|
||||
*/
|
||||
public function after_setup_theme() {
|
||||
public function after_setup_theme(): void {
|
||||
|
||||
foreach ( $this->event_configs as $config ) {
|
||||
$this->add_events( $config->get_events() );
|
||||
@@ -78,7 +79,7 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
|
||||
return $input;
|
||||
}
|
||||
|
||||
$event = wp_parse_args( $this->events[ $filter_name ][ $priority ], [
|
||||
$event = \wp_parse_args( $this->events[ $filter_name ][ $priority ], [
|
||||
'action' => 'start',
|
||||
'category' => null,
|
||||
] );
|
||||
@@ -95,7 +96,7 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
|
||||
/**
|
||||
* @return Stopwatch_Record[]
|
||||
*/
|
||||
public function get_records() {
|
||||
public function get_records(): array {
|
||||
|
||||
$this->stopwatch->stop( 'Toolbar' );
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -29,7 +30,7 @@ class Http_Record_Collector extends Stopwatch_Record_Collector {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function pre_http_request( $false, $args, $url ) {
|
||||
public function pre_http_request( bool $false, array $args, string $url ): bool {
|
||||
|
||||
$this->start( $url, 'http' );
|
||||
|
||||
@@ -49,7 +50,7 @@ class Http_Record_Collector extends Stopwatch_Record_Collector {
|
||||
*
|
||||
* @noinspection MoreThanThreeArgumentsInspection
|
||||
*/
|
||||
public function http_api_debug( $response, $type, $class, $args, $url ) {
|
||||
public function http_api_debug( $response, string $type, $class, array $args, string $url ) {
|
||||
|
||||
$this->stop( $url );
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -29,7 +30,7 @@ class Record implements Record_Interface {
|
||||
* @param string $description Optional description.
|
||||
* @param string $category Optional category.
|
||||
*/
|
||||
public function __construct( $name, $origin, $duration, $description = '', $category = '' ) {
|
||||
public function __construct( string $name, float $origin, float $duration, string $description = '', string $category = '' ) {
|
||||
$this->name = $name;
|
||||
$this->origin = $origin;
|
||||
$this->duration = $duration;
|
||||
@@ -40,14 +41,14 @@ class Record implements Record_Interface {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
public function get_name(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
public function get_description(): string {
|
||||
|
||||
if ( empty( $this->description ) ) {
|
||||
$duration = round( $this->get_duration() * 1000 );
|
||||
@@ -61,21 +62,21 @@ class Record implements Record_Interface {
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function get_origin() {
|
||||
public function get_origin(): float {
|
||||
return $this->origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function get_duration() {
|
||||
public function get_duration(): float {
|
||||
return $this->duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_category() {
|
||||
public function get_category(): string {
|
||||
return $this->category;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
/**
|
||||
* Interface to retrieve a set of records form collector.
|
||||
*/
|
||||
interface Record_Collector_Interface {
|
||||
|
||||
/**
|
||||
* @return Record_Interface[]
|
||||
*/
|
||||
public function get_records();
|
||||
public function get_records(): array;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -10,25 +11,25 @@ interface Record_Interface {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_name();
|
||||
public function get_name(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_description();
|
||||
public function get_description(): string;
|
||||
|
||||
/**
|
||||
* @return float Timestamp of record start.
|
||||
*/
|
||||
public function get_origin();
|
||||
public function get_origin(): float;
|
||||
|
||||
/**
|
||||
* @return float Record duration in seconds.
|
||||
*/
|
||||
public function get_duration();
|
||||
public function get_duration(): float;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_category();
|
||||
public function get_category(): string;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -14,7 +15,7 @@ class Recursive_Record_Iterator extends \ArrayIterator implements \RecursiveIter
|
||||
* @param Record_Interface[] $records Records to process.
|
||||
* @param int $flags Configuration flags.
|
||||
*/
|
||||
public function __construct( array $records, $flags = 0 ) {
|
||||
public function __construct( array $records, int $flags = 0 ) {
|
||||
|
||||
usort( $records, [ $this, 'sort_origin' ] );
|
||||
$end = 0;
|
||||
@@ -43,7 +44,7 @@ class Recursive_Record_Iterator extends \ArrayIterator implements \RecursiveIter
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function sort_origin( Record_Interface $record_a, Record_Interface $record_b ) {
|
||||
protected function sort_origin( Record_Interface $record_a, Record_Interface $record_b ): int {
|
||||
|
||||
$origin_a = $record_a->get_origin();
|
||||
$origin_b = $record_b->get_origin();
|
||||
@@ -58,7 +59,7 @@ class Recursive_Record_Iterator extends \ArrayIterator implements \RecursiveIter
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChildren() {
|
||||
public function hasChildren(): bool {
|
||||
|
||||
return ! empty( $this->children );
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -34,7 +35,7 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function query( $query ) {
|
||||
public function query( $query ): string {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
@@ -50,7 +51,7 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
/**
|
||||
* @return Record[]
|
||||
*/
|
||||
public function get_records() {
|
||||
public function get_records(): array {
|
||||
|
||||
if ( ! $this->is_savequeries() ) {
|
||||
return [];
|
||||
@@ -64,9 +65,9 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_savequeries() {
|
||||
protected function is_savequeries(): bool {
|
||||
|
||||
return defined( 'SAVEQUERIES' ) && SAVEQUERIES;
|
||||
return \defined( 'SAVEQUERIES' ) && SAVEQUERIES;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,13 +78,13 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
||||
*
|
||||
* @return Record
|
||||
*/
|
||||
protected function transform( $key, $query_data ) {
|
||||
protected function transform( int $key, array $query_data ): Record {
|
||||
|
||||
static $last_query_end = 0;
|
||||
|
||||
list( $sql, $duration, $caller ) = $query_data;
|
||||
[ $sql, $duration, $caller ] = $query_data;
|
||||
|
||||
$query_start = isset( $this->query_starts[ $key ] ) ? $this->query_starts[ $key ] : $last_query_end;
|
||||
$query_start = $this->query_starts[ $key ] ?? $last_query_end;
|
||||
$sql = trim( $sql );
|
||||
$category = 'sql-read';
|
||||
if ( 0 === stripos( $sql, 'INSERT' ) || 0 === stripos( $sql, 'UPDATE' ) ) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -19,7 +20,7 @@ class Stopwatch_Record implements Record_Interface {
|
||||
* @param string $name Event name.
|
||||
* @param StopwatchEvent $stopwatch_event Stopwatch event instance.
|
||||
*/
|
||||
public function __construct( $name, StopwatchEvent $stopwatch_event ) {
|
||||
public function __construct( string $name, StopwatchEvent $stopwatch_event ) {
|
||||
$this->name = $name;
|
||||
$this->stopwatch_event = $stopwatch_event;
|
||||
}
|
||||
@@ -27,14 +28,14 @@ class Stopwatch_Record implements Record_Interface {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
public function get_name(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
public function get_description(): string {
|
||||
|
||||
$duration = round( $this->stopwatch_event->getDuration() );
|
||||
$memory = $this->stopwatch_event->getMemory() / 1024 / 1024;
|
||||
@@ -45,21 +46,21 @@ class Stopwatch_Record implements Record_Interface {
|
||||
/**
|
||||
* @return float Timestamp of record start.
|
||||
*/
|
||||
public function get_origin() {
|
||||
public function get_origin(): float {
|
||||
return $this->stopwatch_event->getOrigin() / 1000; // ms to s.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float Record duration in seconds.
|
||||
*/
|
||||
public function get_duration() {
|
||||
public function get_duration(): float {
|
||||
return $this->stopwatch_event->getDuration() / 1000; // ms to s.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_category() {
|
||||
public function get_category(): string {
|
||||
return $this->stopwatch_event->getCategory();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -26,7 +27,7 @@ class Stopwatch_Record_Collector implements Record_Collector_Interface {
|
||||
*
|
||||
* @return StopwatchEvent
|
||||
*/
|
||||
public function start( $name, $category = null ) {
|
||||
public function start( $name, $category = null ): StopwatchEvent {
|
||||
return $this->stopwatch->start( $name, $category );
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ class Stopwatch_Record_Collector implements Record_Collector_Interface {
|
||||
/**
|
||||
* @return Stopwatch_Record[]
|
||||
*/
|
||||
public function get_records() {
|
||||
public function get_records(): array {
|
||||
|
||||
$events = $this->stopwatch->getSectionEvents( '__root__' );
|
||||
|
||||
@@ -66,7 +67,7 @@ class Stopwatch_Record_Collector implements Record_Collector_Interface {
|
||||
*
|
||||
* @return Stopwatch_Record
|
||||
*/
|
||||
protected function transform( $name, StopwatchEvent $event ) {
|
||||
protected function transform( string $name, StopwatchEvent $event ): Stopwatch_Record {
|
||||
|
||||
return new Stopwatch_Record( $name, $event );
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Rarst\Laps\Record;
|
||||
|
||||
@@ -24,14 +25,14 @@ class Timeline_Iterator implements \Iterator {
|
||||
*/
|
||||
public function __construct( Recursive_Record_Iterator $iterator ) {
|
||||
|
||||
$this->origin = $_SERVER['REQUEST_TIME_FLOAT'];
|
||||
$this->origin = filter_var( $_SERVER['REQUEST_TIME_FLOAT'], FILTER_VALIDATE_FLOAT );
|
||||
$this->iterator = $iterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function current() {
|
||||
public function current(): array {
|
||||
|
||||
$data = [];
|
||||
|
||||
@@ -45,7 +46,7 @@ class Timeline_Iterator implements \Iterator {
|
||||
/**
|
||||
* Sets current context to the next set of nested records.
|
||||
*/
|
||||
public function next() {
|
||||
public function next(): void {
|
||||
$this->current = $this->current->getChildren();
|
||||
}
|
||||
|
||||
@@ -54,21 +55,21 @@ class Timeline_Iterator implements \Iterator {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function key() {
|
||||
public function key(): void {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool If current set contains records.
|
||||
*/
|
||||
public function valid() {
|
||||
public function valid(): bool {
|
||||
return (bool) count( $this->current );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind to a topmost record set.
|
||||
*/
|
||||
public function rewind() {
|
||||
public function rewind(): void {
|
||||
$this->total = microtime( true ) - $this->origin;
|
||||
$this->current = $this->iterator;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ class Timeline_Iterator implements \Iterator {
|
||||
*
|
||||
* @return array Record data for display by the template.
|
||||
*/
|
||||
protected function prepare( Record_Interface $record ) {
|
||||
protected function prepare( Record_Interface $record ): array {
|
||||
|
||||
$data = [
|
||||
'description' => $record->get_description(),
|
||||
|
||||
Reference in new issue
Block a user