Raised PHP requirement to 7.1 and updated types.

Fixes #25
This commit is contained in:
Andrey Savchenko committed 2018-11-30 13:58:53 +02:00
1 parent cd55061e69
commit 204c1df755
29 files changed
+115 -75

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@
} }
}, },
"require" : { "require" : {
"php" : ">=5.6", "php" : "^7.1.3",
"composer/installers": "~1.0", "composer/installers": "~1.0",
"symfony/stopwatch" : "^3.4.4", "symfony/stopwatch" : "^3.4.4",
"mustache/mustache" : "~2.4", "mustache/mustache" : "~2.4",
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Event; namespace Rarst\Laps\Event;
@@ -10,7 +11,7 @@ class Core_Events implements Hook_Event_Config_Interface {
/** /**
* @return array * @return array
*/ */
public function get_events() { public function get_events(): array {
$stops = []; $stops = [];
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Event; namespace Rarst\Laps\Event;
@@ -12,11 +13,11 @@ class Genesis_Events implements Hook_Event_Config_Interface {
/** /**
* @return array * @return array
*/ */
public function get_events() { public function get_events(): array {
$events = []; $events = [];
if ( ! function_exists( 'genesis' ) ) { if ( ! \function_exists( 'genesis' ) ) {
return $events; return $events;
} }
+5 -1
View File
@@ -1,11 +1,15 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Event; namespace Rarst\Laps\Event;
/**
* Interface to retrieve configuration array of hook events to track.
*/
interface Hook_Event_Config_Interface { interface Hook_Event_Config_Interface {
/** /**
* @return array * @return array
*/ */
public function get_events(); public function get_events(): array;
} }
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Event; namespace Rarst\Laps\Event;
@@ -12,11 +13,11 @@ class Hybrid_Events implements Hook_Event_Config_Interface {
/** /**
* @return array * @return array
*/ */
public function get_events() { public function get_events(): array {
$events = []; $events = [];
if ( ! function_exists( 'hybrid_get_prefix' ) ) { if ( ! \function_exists( 'hybrid_get_prefix' ) ) {
return $events; return $events;
} }
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Event; namespace Rarst\Laps\Event;
@@ -12,11 +13,11 @@ class THA_Events implements Hook_Event_Config_Interface {
/** /**
* @return array * @return array
*/ */
public function get_events() { public function get_events(): array {
$events = []; $events = [];
if ( ! defined( 'THA_HOOKS_VERSION' ) ) { if ( ! \defined( 'THA_HOOKS_VERSION' ) ) {
return $events; return $events;
} }
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Event; namespace Rarst\Laps\Event;
@@ -10,7 +11,7 @@ class Yoast_Events implements Hook_Event_Config_Interface {
/** /**
* @return array * @return array
*/ */
public function get_events() { public function get_events(): array {
$stops = []; $stops = [];
+5 -4
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Formatter; namespace Rarst\Laps\Formatter;
@@ -42,9 +43,9 @@ class Backtrace_Formatter {
* *
* @return array * @return array
*/ */
public function format( $backtrace ) { public function format( $backtrace ): array {
if ( is_string( $backtrace ) ) { if ( \is_string( $backtrace ) ) {
$backtrace = explode( ', ', $backtrace ); $backtrace = explode( ', ', $backtrace );
} }
@@ -61,7 +62,7 @@ class Backtrace_Formatter {
* *
* @return bool Keep or drop. * @return bool Keep or drop.
*/ */
protected function filter( $item ) { protected function filter( string $item ): bool {
foreach ( self::$skip as $match ) { foreach ( self::$skip as $match ) {
if ( false !== strpos( $item, $match ) ) { if ( false !== strpos( $item, $match ) ) {
@@ -77,7 +78,7 @@ class Backtrace_Formatter {
* *
* @return string * @return string
*/ */
protected function shorten_include( $item ) { protected function shorten_include( string $item ): string {
if ( 0 === strpos( $item, 'include' ) || 0 === strpos( $item, 'require' ) ) { if ( 0 === strpos( $item, 'include' ) || 0 === strpos( $item, 'require' ) ) {
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Manager; namespace Rarst\Laps\Manager;
@@ -19,9 +20,9 @@ class Asset_Manager {
/** /**
* Registers assets and queues as necessary. * Registers assets and queues as necessary.
*/ */
public function enqueue_scripts() { public function enqueue_scripts(): void {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; $suffix = ( \defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_register_script( 'laps', plugins_url( "public/js/laps{$suffix}.js", dirname( __DIR__ ) ), [ 'jquery' ], '3.3.1', true ); wp_register_script( 'laps', plugins_url( "public/js/laps{$suffix}.js", dirname( __DIR__ ) ), [ 'jquery' ], '3.3.1', true );
wp_register_style( 'laps', plugins_url( "public/css/laps{$suffix}.css", dirname( __DIR__ ) ) ); wp_register_style( 'laps', plugins_url( "public/css/laps{$suffix}.css", dirname( __DIR__ ) ) );
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Manager; namespace Rarst\Laps\Manager;
@@ -23,9 +24,9 @@ class Load_Order_Manager {
* *
* @return array * @return array
*/ */
public function pre_update_option_active_plugins( $plugins ) { public function pre_update_option_active_plugins( array $plugins ): array {
$plugin = plugin_basename( dirname( dirname( __DIR__ ) ) . '/laps.php' ); $plugin = plugin_basename( \dirname( __DIR__, 2 ) . '/laps.php' );
$key = array_search( $plugin, $plugins, true ); $key = array_search( $plugin, $plugins, true );
if ( false !== $key && $key > 0 ) { if ( false !== $key && $key > 0 ) {
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Manager; namespace Rarst\Laps\Manager;
@@ -29,7 +30,7 @@ class Toolbar_Manager {
* *
* @param \WP_Admin_Bar $wp_admin_bar WordPress core toolbar object. * @param \WP_Admin_Bar $wp_admin_bar WordPress core toolbar object.
*/ */
public function admin_bar_menu( $wp_admin_bar ) { public function admin_bar_menu( \WP_Admin_Bar $wp_admin_bar ): void {
if ( ! apply_filters( 'laps_can_see', current_user_can( 'manage_options' ) ) ) { if ( ! apply_filters( 'laps_can_see', current_user_can( 'manage_options' ) ) ) {
return; return;
+3 -1
View File
@@ -1,4 +1,6 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps; namespace Rarst\Laps;
/** /**
@@ -14,7 +16,7 @@ class Mustache_Cache_FrozenCache extends \Mustache_Cache_FilesystemCache {
* *
* @return void * @return void
*/ */
public function cache( $key, $value ) { public function cache( $key, $value ): void {
$this->log( $this->log(
\Mustache_Logger::WARNING, \Mustache_Logger::WARNING,
+4 -3
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps; namespace Rarst\Laps;
@@ -48,7 +49,7 @@ class Plugin extends Container {
* *
* @return $this|static * @return $this|static
*/ */
public function register( ServiceProviderInterface $provider, array $values = [] ) { public function register( ServiceProviderInterface $provider, array $values = [] ): self {
$this->providers[] = $provider; $this->providers[] = $provider;
@@ -60,9 +61,9 @@ class Plugin extends Container {
/** /**
* Start Stopwatch and timing plugin load immediately, then set up core events and needed hooks. * Start Stopwatch and timing plugin load immediately, then set up core events and needed hooks.
*/ */
public function run() { public function run(): void {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { if ( \defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return; return;
} }
+5 -1
View File
@@ -1,9 +1,13 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Provider; namespace Rarst\Laps\Provider;
use Rarst\Laps\Plugin; use Rarst\Laps\Plugin;
/**
* Interface for providers that need to boot up once plugin is ready to start.
*/
interface Bootable_Provider_Interface { interface Bootable_Provider_Interface {
/** /**
@@ -11,5 +15,5 @@ interface Bootable_Provider_Interface {
* *
* @return void * @return void
*/ */
public function boot( Plugin $laps ); public function boot( Plugin $laps ): void;
} }
+2 -1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Provider; namespace Rarst\Laps\Provider;
@@ -18,7 +19,7 @@ class Hook_Event_Provider implements ServiceProviderInterface {
/** /**
* @param Container $pimple Container instance. * @param Container $pimple Container instance.
*/ */
public function register( Container $pimple ) { public function register( Container $pimple ): void {
$pimple['hook.events'] = function () { $pimple['hook.events'] = function () {
return [ return [
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Provider; namespace Rarst\Laps\Provider;
@@ -17,7 +18,7 @@ class Manager_Provider implements ServiceProviderInterface, Bootable_Provider_In
/** /**
* @param Container $pimple Container instance. * @param Container $pimple Container instance.
*/ */
public function register( Container $pimple ) { public function register( Container $pimple ): void {
$pimple['managers'] = function ( Plugin $laps ) { $pimple['managers'] = function ( Plugin $laps ) {
return [ return [
@@ -31,7 +32,7 @@ class Manager_Provider implements ServiceProviderInterface, Bootable_Provider_In
/** /**
* @param Plugin $laps Container instance. * @param Plugin $laps Container instance.
*/ */
public function boot( Plugin $laps ) { public function boot( Plugin $laps ): void {
$laps['managers']; $laps['managers'];
} }
} }
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Provider; namespace Rarst\Laps\Provider;
@@ -20,7 +21,7 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
/** /**
* @param Container $pimple Container instance. * @param Container $pimple Container instance.
*/ */
public function register( Container $pimple ) { public function register( Container $pimple ): void {
$pimple['stopwatch'] = $pimple->factory( function () { $pimple['stopwatch'] = $pimple->factory( function () {
return new Stopwatch( true ); return new Stopwatch( true );
@@ -51,7 +52,7 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
/** /**
* @param Plugin $laps Container instance. * @param Plugin $laps Container instance.
*/ */
public function boot( Plugin $laps ) { public function boot( Plugin $laps ): void {
$laps['collectors']; $laps['collectors'];
} }
} }
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -20,11 +21,11 @@ class Core_Load_Collector implements Record_Collector_Interface {
/** /**
* @return Record_Interface[] * @return Record_Interface[]
*/ */
public function get_records() { public function get_records(): array {
global $timestart; global $timestart;
$request_time = $_SERVER['REQUEST_TIME_FLOAT']; $request_time = filter_var( $_SERVER['REQUEST_TIME_FLOAT'], FILTER_VALIDATE_FLOAT );
return [ return [
new Record( 'PHP Load', $request_time, $timestart - $request_time, '', 'php' ), new Record( 'PHP Load', $request_time, $timestart - $request_time, '', 'php' ),
+5 -4
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -37,7 +38,7 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
* *
* @param array $stops Starts and stops to hook. * @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 ); $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. * 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 ) { foreach ( $this->event_configs as $config ) {
$this->add_events( $config->get_events() ); $this->add_events( $config->get_events() );
@@ -78,7 +79,7 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
return $input; return $input;
} }
$event = wp_parse_args( $this->events[ $filter_name ][ $priority ], [ $event = \wp_parse_args( $this->events[ $filter_name ][ $priority ], [
'action' => 'start', 'action' => 'start',
'category' => null, 'category' => null,
] ); ] );
@@ -95,7 +96,7 @@ class Hook_Record_Collector extends Stopwatch_Record_Collector {
/** /**
* @return Stopwatch_Record[] * @return Stopwatch_Record[]
*/ */
public function get_records() { public function get_records(): array {
$this->stopwatch->stop( 'Toolbar' ); $this->stopwatch->stop( 'Toolbar' );
+3 -2
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -29,7 +30,7 @@ class Http_Record_Collector extends Stopwatch_Record_Collector {
* *
* @return boolean * @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' ); $this->start( $url, 'http' );
@@ -49,7 +50,7 @@ class Http_Record_Collector extends Stopwatch_Record_Collector {
* *
* @noinspection MoreThanThreeArgumentsInspection * @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 ); $this->stop( $url );
+7 -6
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -29,7 +30,7 @@ class Record implements Record_Interface {
* @param string $description Optional description. * @param string $description Optional description.
* @param string $category Optional category. * @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->name = $name;
$this->origin = $origin; $this->origin = $origin;
$this->duration = $duration; $this->duration = $duration;
@@ -40,14 +41,14 @@ class Record implements Record_Interface {
/** /**
* @return string * @return string
*/ */
public function get_name() { public function get_name(): string {
return $this->name; return $this->name;
} }
/** /**
* @return string * @return string
*/ */
public function get_description() { public function get_description(): string {
if ( empty( $this->description ) ) { if ( empty( $this->description ) ) {
$duration = round( $this->get_duration() * 1000 ); $duration = round( $this->get_duration() * 1000 );
@@ -61,21 +62,21 @@ class Record implements Record_Interface {
/** /**
* @return float * @return float
*/ */
public function get_origin() { public function get_origin(): float {
return $this->origin; return $this->origin;
} }
/** /**
* @return float * @return float
*/ */
public function get_duration() { public function get_duration(): float {
return $this->duration; return $this->duration;
} }
/** /**
* @return string * @return string
*/ */
public function get_category() { public function get_category(): string {
return $this->category; return $this->category;
} }
} }
+5 -1
View File
@@ -1,11 +1,15 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
/**
* Interface to retrieve a set of records form collector.
*/
interface Record_Collector_Interface { interface Record_Collector_Interface {
/** /**
* @return Record_Interface[] * @return Record_Interface[]
*/ */
public function get_records(); public function get_records(): array;
} }
+6 -5
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -10,25 +11,25 @@ interface Record_Interface {
/** /**
* @return string * @return string
*/ */
public function get_name(); public function get_name(): string;
/** /**
* @return string * @return string
*/ */
public function get_description(); public function get_description(): string;
/** /**
* @return float Timestamp of record start. * @return float Timestamp of record start.
*/ */
public function get_origin(); public function get_origin(): float;
/** /**
* @return float Record duration in seconds. * @return float Record duration in seconds.
*/ */
public function get_duration(); public function get_duration(): float;
/** /**
* @return string * @return string
*/ */
public function get_category(); public function get_category(): string;
} }
+4 -3
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -14,7 +15,7 @@ class Recursive_Record_Iterator extends \ArrayIterator implements \RecursiveIter
* @param Record_Interface[] $records Records to process. * @param Record_Interface[] $records Records to process.
* @param int $flags Configuration flags. * @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' ] ); usort( $records, [ $this, 'sort_origin' ] );
$end = 0; $end = 0;
@@ -43,7 +44,7 @@ class Recursive_Record_Iterator extends \ArrayIterator implements \RecursiveIter
* *
* @return int * @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_a = $record_a->get_origin();
$origin_b = $record_b->get_origin(); $origin_b = $record_b->get_origin();
@@ -58,7 +59,7 @@ class Recursive_Record_Iterator extends \ArrayIterator implements \RecursiveIter
/** /**
* @return bool * @return bool
*/ */
public function hasChildren() { public function hasChildren(): bool {
return ! empty( $this->children ); return ! empty( $this->children );
} }
+8 -7
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -34,7 +35,7 @@ class Sql_Record_Collector implements Record_Collector_Interface {
* *
* @return string * @return string
*/ */
public function query( $query ) { public function query( $query ): string {
global $wpdb; global $wpdb;
@@ -50,7 +51,7 @@ class Sql_Record_Collector implements Record_Collector_Interface {
/** /**
* @return Record[] * @return Record[]
*/ */
public function get_records() { public function get_records(): array {
if ( ! $this->is_savequeries() ) { if ( ! $this->is_savequeries() ) {
return []; return [];
@@ -64,9 +65,9 @@ class Sql_Record_Collector implements Record_Collector_Interface {
/** /**
* @return bool * @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 * @return Record
*/ */
protected function transform( $key, $query_data ) { protected function transform( int $key, array $query_data ): Record {
static $last_query_end = 0; 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 ); $sql = trim( $sql );
$category = 'sql-read'; $category = 'sql-read';
if ( 0 === stripos( $sql, 'INSERT' ) || 0 === stripos( $sql, 'UPDATE' ) ) { if ( 0 === stripos( $sql, 'INSERT' ) || 0 === stripos( $sql, 'UPDATE' ) ) {
+7 -6
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -19,7 +20,7 @@ class Stopwatch_Record implements Record_Interface {
* @param string $name Event name. * @param string $name Event name.
* @param StopwatchEvent $stopwatch_event Stopwatch event instance. * @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->name = $name;
$this->stopwatch_event = $stopwatch_event; $this->stopwatch_event = $stopwatch_event;
} }
@@ -27,14 +28,14 @@ class Stopwatch_Record implements Record_Interface {
/** /**
* @return string * @return string
*/ */
public function get_name() { public function get_name(): string {
return $this->name; return $this->name;
} }
/** /**
* @return string * @return string
*/ */
public function get_description() { public function get_description(): string {
$duration = round( $this->stopwatch_event->getDuration() ); $duration = round( $this->stopwatch_event->getDuration() );
$memory = $this->stopwatch_event->getMemory() / 1024 / 1024; $memory = $this->stopwatch_event->getMemory() / 1024 / 1024;
@@ -45,21 +46,21 @@ class Stopwatch_Record implements Record_Interface {
/** /**
* @return float Timestamp of record start. * @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 $this->stopwatch_event->getOrigin() / 1000; // ms to s.
} }
/** /**
* @return float Record duration in seconds. * @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 $this->stopwatch_event->getDuration() / 1000; // ms to s.
} }
/** /**
* @return string * @return string
*/ */
public function get_category() { public function get_category(): string {
return $this->stopwatch_event->getCategory(); return $this->stopwatch_event->getCategory();
} }
} }
+4 -3
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -26,7 +27,7 @@ class Stopwatch_Record_Collector implements Record_Collector_Interface {
* *
* @return StopwatchEvent * @return StopwatchEvent
*/ */
public function start( $name, $category = null ) { public function start( $name, $category = null ): StopwatchEvent {
return $this->stopwatch->start( $name, $category ); return $this->stopwatch->start( $name, $category );
} }
@@ -47,7 +48,7 @@ class Stopwatch_Record_Collector implements Record_Collector_Interface {
/** /**
* @return Stopwatch_Record[] * @return Stopwatch_Record[]
*/ */
public function get_records() { public function get_records(): array {
$events = $this->stopwatch->getSectionEvents( '__root__' ); $events = $this->stopwatch->getSectionEvents( '__root__' );
@@ -66,7 +67,7 @@ class Stopwatch_Record_Collector implements Record_Collector_Interface {
* *
* @return Stopwatch_Record * @return Stopwatch_Record
*/ */
protected function transform( $name, StopwatchEvent $event ) { protected function transform( string $name, StopwatchEvent $event ): Stopwatch_Record {
return new Stopwatch_Record( $name, $event ); return new Stopwatch_Record( $name, $event );
} }
+8 -7
View File
@@ -1,4 +1,5 @@
<?php <?php
declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record;
@@ -24,14 +25,14 @@ class Timeline_Iterator implements \Iterator {
*/ */
public function __construct( Recursive_Record_Iterator $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; $this->iterator = $iterator;
} }
/** /**
* @return array * @return array
*/ */
public function current() { public function current(): array {
$data = []; $data = [];
@@ -45,7 +46,7 @@ class Timeline_Iterator implements \Iterator {
/** /**
* Sets current context to the next set of nested records. * Sets current context to the next set of nested records.
*/ */
public function next() { public function next(): void {
$this->current = $this->current->getChildren(); $this->current = $this->current->getChildren();
} }
@@ -54,21 +55,21 @@ class Timeline_Iterator implements \Iterator {
* *
* @return void * @return void
*/ */
public function key() { public function key(): void {
} }
/** /**
* @return bool If current set contains records. * @return bool If current set contains records.
*/ */
public function valid() { public function valid(): bool {
return (bool) count( $this->current ); return (bool) count( $this->current );
} }
/** /**
* Rewind to a topmost record set. * Rewind to a topmost record set.
*/ */
public function rewind() { public function rewind(): void {
$this->total = microtime( true ) - $this->origin; $this->total = microtime( true ) - $this->origin;
$this->current = $this->iterator; $this->current = $this->iterator;
} }
@@ -78,7 +79,7 @@ class Timeline_Iterator implements \Iterator {
* *
* @return array Record data for display by the template. * @return array Record data for display by the template.
*/ */
protected function prepare( Record_Interface $record ) { protected function prepare( Record_Interface $record ): array {
$data = [ $data = [
'description' => $record->get_description(), 'description' => $record->get_description(),
+3
View File
@@ -10,6 +10,9 @@ class CoreTest extends LapsTestCase {
public function testCollector() { public function testCollector() {
global $timestart;
$timestart = microtime( true );;
$collector = new Core_Load_Collector(); $collector = new Core_Load_Collector();
$records = $collector->get_records(); $records = $collector->get_records();