Reorganized collector classes.

This commit is contained in:
Andrey Savchenko committed 2018-12-21 15:45:47 +02:00
1 parent fb144ebe01
commit 961019ef74
16 files changed
+46 -34

No files matched your search

+1
View File
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed ### Changed
- required PHP version to 7.1 - required PHP version to 7.1
- organization and names for Record classes
### Deprecated ### Deprecated
- old format of hook events - old format of hook events
+3 -3
View File
@@ -26,17 +26,17 @@
<MixedArgument> <MixedArgument>
<errorLevel type="suppress"> <errorLevel type="suppress">
<file name="src/Provider/Record_Provider.php" /> <file name="src/Provider/Record_Provider.php" />
<file name="src/Record/Hook_Record_Collector.php" /> <file name="src/Record/Collector/Hook_Collector.php" />
</errorLevel> </errorLevel>
</MixedArgument> </MixedArgument>
<MissingClosureParamType> <MissingClosureParamType>
<errorLevel type="suppress"> <errorLevel type="suppress">
<file name="src/Record/Hook_Record_Collector.php" /> <file name="src/Record/Collector/Hook_Collector.php" />
</errorLevel> </errorLevel>
</MissingClosureParamType> </MissingClosureParamType>
<MissingClosureReturnType> <MissingClosureReturnType>
<errorLevel type="suppress"> <errorLevel type="suppress">
<file name="src/Record/Hook_Record_Collector.php" /> <file name="src/Record/Collector/Hook_Collector.php" />
</errorLevel> </errorLevel>
</MissingClosureReturnType> </MissingClosureReturnType>
</issueHandlers> </issueHandlers>
+3 -1
View File
@@ -3,13 +3,15 @@ declare( strict_types=1 );
namespace Rarst\Laps\Event; namespace Rarst\Laps\Event;
use Rarst\Laps\Record\Collector\Hook_Collector;
/** /**
* Interface to retrieve configuration array of hook events to track. * Interface to retrieve configuration array of hook events to track.
*/ */
interface Hook_Event_Config_Interface { interface Hook_Event_Config_Interface {
/** /**
* @see Hook_Record_Collector::add_event() * @see Hook_Collector::add_event()
* *
* @return array[] * @return array[]
*/ */
+1 -1
View File
@@ -32,7 +32,7 @@ class Hook_Formatter {
$closure = new \ReflectionFunction( $callback ); $closure = new \ReflectionFunction( $callback );
$callback = 'closure from ' . $closure->getFileName() . '::' . $closure->getStartLine(); $callback = 'closure from ' . $closure->getFileName() . '::' . $closure->getStartLine();
if ( false !== strpos( $callback, 'Hook_Record_Collector' ) ) { if ( false !== strpos( $callback, 'Hook_Collector' ) ) {
continue; continue;
} }
} elseif ( is_object( $callback ) ) { } elseif ( is_object( $callback ) ) {
+8 -8
View File
@@ -6,11 +6,11 @@ namespace Rarst\Laps\Provider;
use Pimple\Container; use Pimple\Container;
use Pimple\ServiceProviderInterface; use Pimple\ServiceProviderInterface;
use Rarst\Laps\Plugin; use Rarst\Laps\Plugin;
use Rarst\Laps\Record\Core_Load_Collector; use Rarst\Laps\Record\Collector\Core_Load_Collector;
use Rarst\Laps\Record\Hook_Record_Collector; use Rarst\Laps\Record\Collector\Hook_Collector;
use Rarst\Laps\Record\Http_Record_Collector; use Rarst\Laps\Record\Collector\Http_Collector;
use Rarst\Laps\Record\Record_Collector_Interface; use Rarst\Laps\Record\Collector\Record_Collector_Interface;
use Rarst\Laps\Record\Sql_Record_Collector; use Rarst\Laps\Record\Collector\Sql_Collector;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
/** /**
@@ -30,9 +30,9 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
$pimple['collectors'] = function ( Plugin $laps ): array { $pimple['collectors'] = function ( Plugin $laps ): array {
return [ return [
'core' => new Core_Load_Collector(), 'core' => new Core_Load_Collector(),
'hook' => new Hook_Record_Collector( $laps['stopwatch'], $laps['hook.events'] ), 'hook' => new Hook_Collector( $laps['stopwatch'], $laps['hook.events'] ),
'http' => new Http_Record_Collector( $laps['stopwatch'] ), 'http' => new Http_Collector( $laps['stopwatch'] ),
'sql' => new Sql_Record_Collector(), 'sql' => new Sql_Collector(),
]; ];
}; };
@@ -1,7 +1,10 @@
<?php <?php
declare( strict_types=1 ); declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record\Collector;
use Rarst\Laps\Record\Record;
use Rarst\Laps\Record\Record_Interface;
/** /**
* Covers pre–plugin load time from available data. * Covers pre–plugin load time from available data.
@@ -1,17 +1,18 @@
<?php <?php
declare( strict_types=1 ); declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record\Collector;
use Rarst\Laps\Event\Hook_Event_Config_Interface; use Rarst\Laps\Event\Hook_Event_Config_Interface;
use Rarst\Laps\Formatter\Hook_Formatter; use Rarst\Laps\Formatter\Hook_Formatter;
use Rarst\Laps\Record\Stopwatch_Record;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent; use Symfony\Component\Stopwatch\StopwatchEvent;
/** /**
* Processes events based on hooked starts and stops. * Processes events based on hooked starts and stops.
*/ */
class Hook_Record_Collector extends Stopwatch_Record_Collector { class Hook_Collector extends Stopwatch_Collector {
/** @var Hook_Event_Config_Interface[] $event_configs */ /** @var Hook_Event_Config_Interface[] $event_configs */
protected $event_configs = []; protected $event_configs = [];
@@ -1,16 +1,17 @@
<?php <?php
declare( strict_types=1 ); declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record\Collector;
use Rarst\Laps\Formatter\Backtrace_Formatter; use Rarst\Laps\Formatter\Backtrace_Formatter;
use Rarst\Laps\Record\Stopwatch_Record;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent; use Symfony\Component\Stopwatch\StopwatchEvent;
/** /**
* Captures time of network requests made with HTTP API. * Captures time of network requests made with HTTP API.
*/ */
class Http_Record_Collector extends Stopwatch_Record_Collector { class Http_Collector extends Stopwatch_Collector {
/** @var Backtrace_Formatter */ /** @var Backtrace_Formatter */
private $formatter; private $formatter;
@@ -1,7 +1,9 @@
<?php <?php
declare( strict_types=1 ); declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record\Collector;
use Rarst\Laps\Record\Record_Interface;
/** /**
* Interface to retrieve a set of records form collector. * Interface to retrieve a set of records form collector.
@@ -1,14 +1,15 @@
<?php <?php
declare( strict_types=1 ); declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record\Collector;
use Rarst\Laps\Formatter\Backtrace_Formatter; use Rarst\Laps\Formatter\Backtrace_Formatter;
use Rarst\Laps\Record\Record;
/** /**
* Processes SQL events from data logged by wpdb. * Processes SQL events from data logged by wpdb.
*/ */
class Sql_Record_Collector implements Record_Collector_Interface { class Sql_Collector implements Record_Collector_Interface {
/** @var array $query_starts Log of query start times. */ /** @var array $query_starts Log of query start times. */
protected $query_starts = []; protected $query_starts = [];
@@ -1,15 +1,16 @@
<?php <?php
declare( strict_types=1 ); declare( strict_types=1 );
namespace Rarst\Laps\Record; namespace Rarst\Laps\Record\Collector;
use Rarst\Laps\Record\Stopwatch_Record;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent; use Symfony\Component\Stopwatch\StopwatchEvent;
/** /**
* Generic Stopwatch–based collector. Can be used by itself or extended. * Generic Stopwatch–based collector. Can be used by itself or extended.
*/ */
class Stopwatch_Record_Collector implements Record_Collector_Interface { class Stopwatch_Collector implements Record_Collector_Interface {
/** @var Stopwatch $stopwatch */ /** @var Stopwatch $stopwatch */
protected $stopwatch; protected $stopwatch;
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Rarst\Laps\Tests\Record; namespace Rarst\Laps\Tests\Record;
use Rarst\Laps\Record\Core_Load_Collector; use Rarst\Laps\Record\Collector\Core_Load_Collector;
use Rarst\Laps\Record\Record_Interface; use Rarst\Laps\Record\Record_Interface;
use Rarst\Laps\Tests\LapsTestCase; use Rarst\Laps\Tests\LapsTestCase;
+2 -2
View File
@@ -4,7 +4,7 @@ declare( strict_types=1 );
namespace Rarst\Laps\Tests\Record; namespace Rarst\Laps\Tests\Record;
use Rarst\Laps\Event\Core_Events; use Rarst\Laps\Event\Core_Events;
use Rarst\Laps\Record\Hook_Record_Collector; use Rarst\Laps\Record\Collector\Hook_Collector;
use Rarst\Laps\Tests\LapsTestCase; use Rarst\Laps\Tests\LapsTestCase;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
@@ -13,7 +13,7 @@ class HookTest extends LapsTestCase {
public function testCollector() { public function testCollector() {
$stopwatch = new Stopwatch(); $stopwatch = new Stopwatch();
$collector = new Hook_Record_Collector( $stopwatch, [ 'core' => new Core_Events() ] ); $collector = new Hook_Collector( $stopwatch, [ 'core' => new Core_Events() ] );
$this->assertTrue( $stopwatch->isStarted( 'Plugins Load' ) ); $this->assertTrue( $stopwatch->isStarted( 'Plugins Load' ) );
$this->assertTrue( has_action( 'after_setup_theme', [ $collector, 'after_setup_theme' ] ) ); $this->assertTrue( has_action( 'after_setup_theme', [ $collector, 'after_setup_theme' ] ) );
+2 -2
View File
@@ -3,7 +3,7 @@
namespace Rarst\Laps\Tests\Record; namespace Rarst\Laps\Tests\Record;
use Brain\Monkey\Functions; use Brain\Monkey\Functions;
use Rarst\Laps\Record\Http_Record_Collector; use Rarst\Laps\Record\Collector\Http_Collector;
use Rarst\Laps\Tests\LapsTestCase; use Rarst\Laps\Tests\LapsTestCase;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
@@ -16,7 +16,7 @@ class HttpTest extends LapsTestCase {
$stopwatch = new Stopwatch(); $stopwatch = new Stopwatch();
$url = 'https://example.com/'; $url = 'https://example.com/';
$collector = new Http_Record_Collector( $stopwatch ); $collector = new Http_Collector( $stopwatch );
$this->assertTrue( has_action( 'pre_http_request', [ $collector, 'pre_http_request' ] ) ); $this->assertTrue( has_action( 'pre_http_request', [ $collector, 'pre_http_request' ] ) );
$this->assertTrue( has_action( 'http_api_debug', [ $collector, 'http_api_debug' ] ) ); $this->assertTrue( has_action( 'http_api_debug', [ $collector, 'http_api_debug' ] ) );
+3 -3
View File
@@ -4,13 +4,13 @@ namespace Rarst\Laps\Tests\Record;
use Brain\Monkey\Functions; use Brain\Monkey\Functions;
use Rarst\Laps\Record\Record; use Rarst\Laps\Record\Record;
use Rarst\Laps\Record\Sql_Record_Collector; use Rarst\Laps\Record\Collector\Sql_Collector;
use Rarst\Laps\Tests\LapsTestCase; use Rarst\Laps\Tests\LapsTestCase;
class SqlTest extends LapsTestCase { class SqlTest extends LapsTestCase {
/** /**
* @covers \Rarst\Laps\Record\Sql_Record_Collector * @covers \Rarst\Laps\Record\Collector\Sql_Collector
*/ */
public function testCollector() { public function testCollector() {
@@ -22,7 +22,7 @@ class SqlTest extends LapsTestCase {
} }
Functions\expect( 'wp_normalize_path' )->zeroOrMoreTimes()->andReturnFirstArg(); Functions\expect( 'wp_normalize_path' )->zeroOrMoreTimes()->andReturnFirstArg();
$collector = new Sql_Record_Collector(); $collector = new Sql_Collector();
$this->assertTrue( has_filter( 'query', [ $collector, 'query' ] ) ); $this->assertTrue( has_filter( 'query', [ $collector, 'query' ] ) );
+3 -3
View File
@@ -3,7 +3,7 @@
namespace Rarst\Laps\Tests\Record; namespace Rarst\Laps\Tests\Record;
use Rarst\Laps\Record\Stopwatch_Record; use Rarst\Laps\Record\Stopwatch_Record;
use Rarst\Laps\Record\Stopwatch_Record_Collector; use Rarst\Laps\Record\Collector\Stopwatch_Collector;
use Rarst\Laps\Tests\LapsTestCase; use Rarst\Laps\Tests\LapsTestCase;
use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent; use Symfony\Component\Stopwatch\StopwatchEvent;
@@ -11,11 +11,11 @@ use Symfony\Component\Stopwatch\StopwatchEvent;
class StopwatchTest extends LapsTestCase { class StopwatchTest extends LapsTestCase {
/** /**
* @covers \Rarst\Laps\Record\Stopwatch_Record_Collector * @covers \Rarst\Laps\Record\Collector\Stopwatch_Collector
*/ */
public function testCollector() { public function testCollector() {
$collector = new Stopwatch_Record_Collector( new Stopwatch() ); $collector = new Stopwatch_Collector( new Stopwatch() );
$collector->start( 'Event', 'info' ); $collector->start( 'Event', 'info' );
$collector->start( 'Not stopped', 'info' ); $collector->start( 'Not stopped', 'info' );