Moved Benchmark classes into Debug namespace. Refactored them to current styleguide.

This commit is contained in:
Lonnie Ezell 2015-11-30 23:01:44 -06:00
parent 5eb3b0cb2f
commit ad5f9f7a44
6 changed files with 16 additions and 16 deletions

View File

@ -64,8 +64,8 @@ class AutoloadConfig
$this->classmap = [
'CodeIgniter\Loader' => BASEPATH.'Loader.php',
'CodeIgniter\Controller' => BASEPATH.'Controller.php',
'CodeIgniter\Benchmark\Timer' => BASEPATH.'Benchmark/Timer.php',
'CodeIgniter\Benchmark\Iterator' => BASEPATH.'Benchmark/Iterator.php',
'CodeIgniter\Debug\Timer' => BASEPATH.'Debug/Timer.php',
'CodeIgniter\Debug\Iterator' => BASEPATH.'Debug/Iterator.php',
'CodeIgniter\Config\BaseConfig' => BASEPATH.'Config/BaseConfig.php',
'CodeIgniter\HTTP\Message' => BASEPATH.'HTTP/Message.php',
'CodeIgniter\HTTP\Request' => BASEPATH.'HTTP/Request.php',

View File

@ -40,14 +40,14 @@ class Services {
public static function timer()
{
return new \CodeIgniter\Benchmark\Timer();
return new \CodeIgniter\Debug\Timer();
}
//--------------------------------------------------------------------
public static function iterator()
{
return new \CodeIgniter\Benchmark\Iterator();
return new \CodeIgniter\Debug\Iterator();
}
//--------------------------------------------------------------------

View File

@ -155,7 +155,7 @@ else
$output = ob_get_contents();
ob_end_clean();
$output = str_replace('{elapsed_time}', $benchmark->elapsedTime('total_execution'), $output);
$output = str_replace('{elapsed_time}', $benchmark->getElapsedTime('total_execution'), $output);
$response->setBody($output);

View File

@ -1,4 +1,4 @@
<?php namespace CodeIgniter\Benchmark;
<?php namespace CodeIgniter\Debug;
class Iterator
{

View File

@ -1,4 +1,4 @@
<?php namespace CodeIgniter\Benchmark;
<?php namespace CodeIgniter\Debug;
/**
* Class Timer
@ -31,7 +31,7 @@ class Timer
*
* @param string $name The name of this timer.
*/
public function start($name)
public function start(string $name)
{
$this->timers[strtolower($name)] = [
'start' => microtime(true),
@ -49,7 +49,7 @@ class Timer
*
* @param string $name The name of this timer.
*/
public function stop($name)
public function stop(string $name)
{
$name = strtolower($name);
@ -73,7 +73,7 @@ class Timer
* Returns a float representing the number of
* seconds elapsed while that timer was running.
*/
public function elapsedTime($name, $decimals = 4)
public function getElapsedTime(string $name, int $decimals = 4)
{
$name = strtolower($name);
@ -101,7 +101,7 @@ class Timer
*
* @return array
*/
public function timers($decimals = 4)
public function getTimers(int $decimals = 4)
{
$timers = $this->timers;

View File

@ -2,7 +2,7 @@
require_once 'system/Benchmark/Timer.php';
use CodeIgniter\Benchmark\Timer;
use CodeIgniter\Debug\Timer;
class DITest extends PHPUnit_Framework_TestCase {
@ -27,7 +27,7 @@ class DITest extends PHPUnit_Framework_TestCase {
sleep(1);
$timer->stop('test1');
$timers = $timer->timers();
$timers = $timer->getTimers();
$this->assertTrue(count($timers) === 1, "No timers were stored.");
$this->assertArrayHasKey('test1', $timers, 'No "test1" array found.');
@ -49,7 +49,7 @@ class DITest extends PHPUnit_Framework_TestCase {
$timer->start('test1');
sleep(1);
$timers = $timer->timers();
$timers = $timer->getTimers();
$this->assertArrayHasKey('duration', $timers['test1'], "No duration was calculated.");
$this->assertGreaterThanOrEqual(1.0, $timers['test1']['duration']);
@ -65,11 +65,11 @@ class DITest extends PHPUnit_Framework_TestCase {
sleep(1);
$timer->stop('test1');
$timers = $timer->timers();
$timers = $timer->getTimers();
$expected = $timers['test1']['duration'];
$this->assertEquals($expected, $timer->elapsedTime('test1'));
$this->assertEquals($expected, $timer->getElapsedTime('test1'));
}
//--------------------------------------------------------------------