Completed
Push — master ( 95d2b9...51c010 )
by Jacob
02:22
created
tests/unit/ConsoleTest.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -5,112 +5,112 @@
 block discarded – undo
5 5
 class ConsoleTest extends PHPUnit_Framework_TestCase
6 6
 {
7 7
 
8
-    public function __construct()
9
-    {
10
-    }
11
-
12
-    public function testLog()
13
-    {
14
-        $data = array(
15
-            'key' => 'value'
16
-        );
17
-
18
-        $console = new Console();
19
-        $console->log($data);
20
-        $store = $this->getProtectedStore($console);
21
-        $log = array_pop($store);
22
-
23
-        $this->assertSame($data, $log['data']);
24
-        $this->assertEquals('log', $log['type']);
25
-    }
26
-
27
-    public function testLogMemory()
28
-    {
29
-        $data = array(
30
-            'key' => 'value'
31
-        );
32
-        $memory = strlen(serialize($data));
33
-        $name = 'Test Array';
34
-
35
-        $console = new Console();
36
-        $console->logMemory($data, $name);
37
-        $store = $this->getProtectedStore($console);
38
-        $log = array_pop($store);
39
-
40
-        $this->assertEquals($name, $log['name']);
41
-        $this->assertEquals($memory, $log['data']);
42
-        $this->assertEquals('array', $log['data_type']);
43
-        $this->assertEquals('memory', $log['type']);
44
-    }
45
-
46
-    public function testLogError()
47
-    {
48
-        $error = new Exception('Test Exception');
49
-
50
-        $console = new Console();
51
-        $console->logError($error);
52
-        $store = $this->getProtectedStore($console);
53
-        $log = array_pop($store);
54
-
55
-        $this->assertEquals($error->getMessage(), $log['data']);
56
-        $this->assertEquals($error->getFile(), $log['file']);
57
-        $this->assertEquals($error->getLine(), $log['line']);
58
-        $this->assertEquals('error', $log['type']);
59
-
60
-        $error = new Exception('Test Exception');
61
-        $message = 'override message';
62
-
63
-        $console = new Console();
64
-        $console->logError($error, $message);
65
-        $store = $this->getProtectedStore($console);
66
-        $log = array_pop($store);
67
-
68
-        $this->assertEquals($message, $log['data']);
69
-    }
70
-
71
-    public function testLogSpeed()
72
-    {
73
-        $name = 'Test Speed';
74
-
75
-        $console = new Console();
76
-        $console->logSpeed($name);
77
-        $store = $this->getProtectedStore($console);
78
-        $log = array_pop($store);
79
-
80
-        $this->assertEquals($name, $log['name']);
81
-        $this->assertEquals('speed', $log['type']);
82
-    }
83
-
84
-    public function testGetLogs()
85
-    {
86
-        $store = array(
87
-            array(
88
-                'data' => 'a string',
89
-                'type' => 'log'
90
-            ),
91
-            array(
92
-                'name' => '',
93
-                'data' => 123,
94
-                'data_type' => 'array',
95
-                'type' => 'memory'
96
-            )
97
-        );
98
-
99
-        $console = new Console();
100
-
101
-        $reflectedConsole = new ReflectionClass(get_class($console));
102
-        $reflectedProperty = $reflectedConsole->getProperty('store');
103
-        $reflectedProperty->setAccessible(true);
104
-        $reflectedProperty->setValue($console, $store);
105
-
106
-        $this->assertSame($store, $console->getLogs());
107
-    }
108
-
109
-    protected function getProtectedStore(Console $console)
110
-    {
111
-        $reflectedConsole = new ReflectionClass(get_class($console));
112
-        $reflectedProperty = $reflectedConsole->getProperty('store');
113
-        $reflectedProperty->setAccessible(true);
114
-        return $reflectedProperty->getValue($console);
115
-    }
8
+	public function __construct()
9
+	{
10
+	}
11
+
12
+	public function testLog()
13
+	{
14
+		$data = array(
15
+			'key' => 'value'
16
+		);
17
+
18
+		$console = new Console();
19
+		$console->log($data);
20
+		$store = $this->getProtectedStore($console);
21
+		$log = array_pop($store);
22
+
23
+		$this->assertSame($data, $log['data']);
24
+		$this->assertEquals('log', $log['type']);
25
+	}
26
+
27
+	public function testLogMemory()
28
+	{
29
+		$data = array(
30
+			'key' => 'value'
31
+		);
32
+		$memory = strlen(serialize($data));
33
+		$name = 'Test Array';
34
+
35
+		$console = new Console();
36
+		$console->logMemory($data, $name);
37
+		$store = $this->getProtectedStore($console);
38
+		$log = array_pop($store);
39
+
40
+		$this->assertEquals($name, $log['name']);
41
+		$this->assertEquals($memory, $log['data']);
42
+		$this->assertEquals('array', $log['data_type']);
43
+		$this->assertEquals('memory', $log['type']);
44
+	}
45
+
46
+	public function testLogError()
47
+	{
48
+		$error = new Exception('Test Exception');
49
+
50
+		$console = new Console();
51
+		$console->logError($error);
52
+		$store = $this->getProtectedStore($console);
53
+		$log = array_pop($store);
54
+
55
+		$this->assertEquals($error->getMessage(), $log['data']);
56
+		$this->assertEquals($error->getFile(), $log['file']);
57
+		$this->assertEquals($error->getLine(), $log['line']);
58
+		$this->assertEquals('error', $log['type']);
59
+
60
+		$error = new Exception('Test Exception');
61
+		$message = 'override message';
62
+
63
+		$console = new Console();
64
+		$console->logError($error, $message);
65
+		$store = $this->getProtectedStore($console);
66
+		$log = array_pop($store);
67
+
68
+		$this->assertEquals($message, $log['data']);
69
+	}
70
+
71
+	public function testLogSpeed()
72
+	{
73
+		$name = 'Test Speed';
74
+
75
+		$console = new Console();
76
+		$console->logSpeed($name);
77
+		$store = $this->getProtectedStore($console);
78
+		$log = array_pop($store);
79
+
80
+		$this->assertEquals($name, $log['name']);
81
+		$this->assertEquals('speed', $log['type']);
82
+	}
83
+
84
+	public function testGetLogs()
85
+	{
86
+		$store = array(
87
+			array(
88
+				'data' => 'a string',
89
+				'type' => 'log'
90
+			),
91
+			array(
92
+				'name' => '',
93
+				'data' => 123,
94
+				'data_type' => 'array',
95
+				'type' => 'memory'
96
+			)
97
+		);
98
+
99
+		$console = new Console();
100
+
101
+		$reflectedConsole = new ReflectionClass(get_class($console));
102
+		$reflectedProperty = $reflectedConsole->getProperty('store');
103
+		$reflectedProperty->setAccessible(true);
104
+		$reflectedProperty->setValue($console, $store);
105
+
106
+		$this->assertSame($store, $console->getLogs());
107
+	}
108
+
109
+	protected function getProtectedStore(Console $console)
110
+	{
111
+		$reflectedConsole = new ReflectionClass(get_class($console));
112
+		$reflectedProperty = $reflectedConsole->getProperty('store');
113
+		$reflectedProperty->setAccessible(true);
114
+		return $reflectedProperty->getValue($console);
115
+	}
116 116
 }
Please login to merge, or discard this patch.
src/Console.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -15,88 +15,88 @@
 block discarded – undo
15 15
 class Console
16 16
 {
17 17
 
18
-    /** @var  array */
19
-    protected $store = array();
18
+	/** @var  array */
19
+	protected $store = array();
20 20
 
21
-    /**
22
-     * Logs data to the console
23
-     * Accepts any data type
24
-     *
25
-     * @param mixed $data
26
-     */
27
-    public function log($data)
28
-    {
29
-        array_push($this->store, array(
30
-          'data' => $data,
31
-          'type' => 'log'
32
-        ));
33
-    }
21
+	/**
22
+	 * Logs data to the console
23
+	 * Accepts any data type
24
+	 *
25
+	 * @param mixed $data
26
+	 */
27
+	public function log($data)
28
+	{
29
+		array_push($this->store, array(
30
+		  'data' => $data,
31
+		  'type' => 'log'
32
+		));
33
+	}
34 34
 
35
-    /**
36
-     * Logs memory usage of a variable
37
-     * If no parameter is passed in, logs current memory usage
38
-     *
39
-     * @param mixed $object
40
-     * @param string $name
41
-     */
42
-    public function logMemory($object = null, $name = 'PHP')
43
-    {
44
-        $memory = memory_get_usage();
45
-        $data_type = '';
46
-        if (!is_null($object)) {
47
-            $memory = strlen(serialize($object));
48
-            $data_type = gettype($object);
49
-        }
35
+	/**
36
+	 * Logs memory usage of a variable
37
+	 * If no parameter is passed in, logs current memory usage
38
+	 *
39
+	 * @param mixed $object
40
+	 * @param string $name
41
+	 */
42
+	public function logMemory($object = null, $name = 'PHP')
43
+	{
44
+		$memory = memory_get_usage();
45
+		$data_type = '';
46
+		if (!is_null($object)) {
47
+			$memory = strlen(serialize($object));
48
+			$data_type = gettype($object);
49
+		}
50 50
 
51
-        array_push($this->store, array(
52
-            'name'      => $name,
53
-            'data'      => $memory,
54
-            'data_type' => $data_type,
55
-            'type'      => 'memory'
56
-        ));
57
-    }
51
+		array_push($this->store, array(
52
+			'name'      => $name,
53
+			'data'      => $memory,
54
+			'data_type' => $data_type,
55
+			'type'      => 'memory'
56
+		));
57
+	}
58 58
 
59
-    /**
60
-     * Logs exception with optional message override
61
-     *
62
-     * @param Exception $exception
63
-     * @param string    $message
64
-     */
65
-    public function logError(Exception $exception, $message = '')
66
-    {
67
-        if (empty($message)) {
68
-            $message = $exception->getMessage();
69
-        }
59
+	/**
60
+	 * Logs exception with optional message override
61
+	 *
62
+	 * @param Exception $exception
63
+	 * @param string    $message
64
+	 */
65
+	public function logError(Exception $exception, $message = '')
66
+	{
67
+		if (empty($message)) {
68
+			$message = $exception->getMessage();
69
+		}
70 70
 
71
-        array_push($this->store, array(
72
-            'data' => $message,
73
-            'file' => $exception->getFile(),
74
-            'line' => $exception->getLine(),
75
-            'type' => 'error'
76
-        ));
77
-    }
71
+		array_push($this->store, array(
72
+			'data' => $message,
73
+			'file' => $exception->getFile(),
74
+			'line' => $exception->getLine(),
75
+			'type' => 'error'
76
+		));
77
+	}
78 78
 
79
-    /**
80
-     * Logs current time with optional message
81
-     *
82
-     * @param string $name
83
-     */
84
-    public function logSpeed($name = 'Point in Time')
85
-    {
86
-        array_push($this->store, array(
87
-            'data' => microtime(true),
88
-            'name' => $name,
89
-            'type' => 'speed'
90
-        ));
91
-    }
79
+	/**
80
+	 * Logs current time with optional message
81
+	 *
82
+	 * @param string $name
83
+	 */
84
+	public function logSpeed($name = 'Point in Time')
85
+	{
86
+		array_push($this->store, array(
87
+			'data' => microtime(true),
88
+			'name' => $name,
89
+			'type' => 'speed'
90
+		));
91
+	}
92 92
 
93
-    /**
94
-     * Returns the collected logs
95
-     *
96
-     * @returns array
97
-     */
98
-    public function getLogs()
99
-    {
100
-        return $this->store;
101
-    }
93
+	/**
94
+	 * Returns the collected logs
95
+	 *
96
+	 * @returns array
97
+	 */
98
+	public function getLogs()
99
+	{
100
+		return $this->store;
101
+	}
102 102
 }
Please login to merge, or discard this patch.
tests/unit/DisplayTest.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -5,29 +5,29 @@
 block discarded – undo
5 5
 class DisplayTest extends PHPUnit_Framework_TestCase
6 6
 {
7 7
 
8
-    public function testGetReadableTime()
9
-    {
10
-        $test_input = array(
11
-            '.032432' => '32.432 ms',
12
-            '24.3781' => '24.378 s',
13
-            '145.123' => '2.419 m'
14
-        );
8
+	public function testGetReadableTime()
9
+	{
10
+		$test_input = array(
11
+			'.032432' => '32.432 ms',
12
+			'24.3781' => '24.378 s',
13
+			'145.123' => '2.419 m'
14
+		);
15 15
 
16
-        foreach ($test_input as $input => $expected_return) {
17
-            $this->assertEquals($expected_return, Display::getReadableTime($input));
18
-        }
19
-    }
16
+		foreach ($test_input as $input => $expected_return) {
17
+			$this->assertEquals($expected_return, Display::getReadableTime($input));
18
+		}
19
+	}
20 20
 
21
-    public function testGetReadableMemory()
22
-    {
23
-        $test_input = array(
24
-            '314'     => '314 b',
25
-            '7403'    => '7.23 k',
26
-            '2589983' => '2.47 M'
27
-        );
21
+	public function testGetReadableMemory()
22
+	{
23
+		$test_input = array(
24
+			'314'     => '314 b',
25
+			'7403'    => '7.23 k',
26
+			'2589983' => '2.47 M'
27
+		);
28 28
 
29
-        foreach ($test_input as $input => $expected_return) {
30
-            $this->assertEquals($expected_return, Display::getReadableMemory($input));
31
-        }
32
-    }
29
+		foreach ($test_input as $input => $expected_return) {
30
+			$this->assertEquals($expected_return, Display::getReadableMemory($input));
31
+		}
32
+	}
33 33
 }
Please login to merge, or discard this patch.
src/PhpQuickProfiler.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -15,136 +15,136 @@
 block discarded – undo
15 15
 class PhpQuickProfiler
16 16
 {
17 17
 
18
-    /** @var  Console */
19
-    protected $console;
20
-
21
-    /** @var  integer */
22
-    protected $startTime;
23
-
24
-    /** @var  object */
25
-    protected $pdo;
26
-
27
-    /**
28
-     * @param Console $console
29
-     * @param object  $pdo
30
-     * @param integer $startTime
31
-     */
32
-    public function __construct(Console $console, $pdo = null, $startTime = null)
33
-    {
34
-        $this->console = $console;
35
-        $this->pdo = $pdo;
36
-
37
-        if (is_null($startTime)) {
38
-            $startTime = microtime(true);
39
-        }
40
-        $this->startTime = $startTime;
41
-    }
42
-
43
-    /**
44
-     * Get data about files loaded for the application to current point
45
-     *
46
-     * @returns array
47
-     */
48
-    public function gatherFileData()
49
-    {
50
-        $files = get_included_files();
51
-        $data = array();
52
-        foreach ($files as $file) {
53
-            array_push($data, array(
54
-                'name' => $file,
55
-                'size' => filesize($file)
56
-            ));
57
-        }
58
-        return $data;
59
-    }
60
-
61
-    /**
62
-     * Get data about memory usage of the application
63
-     *
64
-     * @returns array
65
-     */
66
-    public function gatherMemoryData()
67
-    {
68
-        $usedMemory = memory_get_peak_usage();
69
-        $allowedMemory = ini_get('memory_limit');
70
-        return array(
71
-            'used'    => $usedMemory,
72
-            'allowed' => $allowedMemory
73
-        );
74
-    }
75
-
76
-    /**
77
-     * Get data about sql usage of the application
78
-     *
79
-     * @param array $profiledQueries
80
-     * @returns array
81
-     */
82
-    public function gatherQueryData(array $profiledQueries)
83
-    {
84
-        $data = array();
85
-        foreach ($profiledQueries as $query) {
86
-            if ($query['function'] !== 'perform') {
87
-                continue;
88
-            }
89
-
90
-            array_push($data, array(
91
-                'sql'     => $query['statement'],
92
-                'explain' => $this->explainQuery($query['statement'], $query['bind_values']),
93
-                'time'    => $query['duration']
94
-            ));
95
-        }
96
-        return $data;
97
-    }
98
-
99
-    /**
100
-     * Attempts to explain a query
101
-     *
102
-     * @param string $query
103
-     * @param array  $parameters
104
-     * @return array
105
-     */
106
-    protected function explainQuery($query, $parameters)
107
-    {
108
-        $query = "EXPLAIN {$query}";
109
-        try {
110
-            $statement = $this->pdo->prepare($query);
111
-            $statement->execute($parameters);
112
-            return $statement->fetch(\PDO::FETCH_ASSOC);
113
-        } catch (\Exception $e) {
114
-            echo $e->getMessage();
115
-        }
116
-        return '';
117
-    }
118
-
119
-    /**
120
-     * Get data about speed of the application
121
-     *
122
-     * @returns array
123
-     */
124
-    public function gatherSpeedData()
125
-    {
126
-        $elapsedTime = microtime(true) - $this->startTime;
127
-        $allowedTime = ini_get('max_execution_time');
128
-        return array(
129
-            'elapsed' => $elapsedTime,
130
-            'allowed' => $allowedTime
131
-        );
132
-    }
133
-
134
-    /**
135
-     * Triggers end display of the profiling data
136
-     *
137
-     * @param Display $display
138
-     * @param array   $profiledQueries
139
-     */
140
-    public function display(Display $display, array $profiledQueries = array())
141
-    {
142
-        $display->setConsole($this->console);
143
-        $display->setFileData($this->gatherFileData());
144
-        $display->setMemoryData($this->gatherMemoryData());
145
-        $display->setQueryData($this->gatherQueryData($profiledQueries));
146
-        $display->setSpeedData($this->gatherSpeedData());
147
-
148
-        $display();
149
-    }
18
+	/** @var  Console */
19
+	protected $console;
20
+
21
+	/** @var  integer */
22
+	protected $startTime;
23
+
24
+	/** @var  object */
25
+	protected $pdo;
26
+
27
+	/**
28
+	 * @param Console $console
29
+	 * @param object  $pdo
30
+	 * @param integer $startTime
31
+	 */
32
+	public function __construct(Console $console, $pdo = null, $startTime = null)
33
+	{
34
+		$this->console = $console;
35
+		$this->pdo = $pdo;
36
+
37
+		if (is_null($startTime)) {
38
+			$startTime = microtime(true);
39
+		}
40
+		$this->startTime = $startTime;
41
+	}
42
+
43
+	/**
44
+	 * Get data about files loaded for the application to current point
45
+	 *
46
+	 * @returns array
47
+	 */
48
+	public function gatherFileData()
49
+	{
50
+		$files = get_included_files();
51
+		$data = array();
52
+		foreach ($files as $file) {
53
+			array_push($data, array(
54
+				'name' => $file,
55
+				'size' => filesize($file)
56
+			));
57
+		}
58
+		return $data;
59
+	}
60
+
61
+	/**
62
+	 * Get data about memory usage of the application
63
+	 *
64
+	 * @returns array
65
+	 */
66
+	public function gatherMemoryData()
67
+	{
68
+		$usedMemory = memory_get_peak_usage();
69
+		$allowedMemory = ini_get('memory_limit');
70
+		return array(
71
+			'used'    => $usedMemory,
72
+			'allowed' => $allowedMemory
73
+		);
74
+	}
75
+
76
+	/**
77
+	 * Get data about sql usage of the application
78
+	 *
79
+	 * @param array $profiledQueries
80
+	 * @returns array
81
+	 */
82
+	public function gatherQueryData(array $profiledQueries)
83
+	{
84
+		$data = array();
85
+		foreach ($profiledQueries as $query) {
86
+			if ($query['function'] !== 'perform') {
87
+				continue;
88
+			}
89
+
90
+			array_push($data, array(
91
+				'sql'     => $query['statement'],
92
+				'explain' => $this->explainQuery($query['statement'], $query['bind_values']),
93
+				'time'    => $query['duration']
94
+			));
95
+		}
96
+		return $data;
97
+	}
98
+
99
+	/**
100
+	 * Attempts to explain a query
101
+	 *
102
+	 * @param string $query
103
+	 * @param array  $parameters
104
+	 * @return array
105
+	 */
106
+	protected function explainQuery($query, $parameters)
107
+	{
108
+		$query = "EXPLAIN {$query}";
109
+		try {
110
+			$statement = $this->pdo->prepare($query);
111
+			$statement->execute($parameters);
112
+			return $statement->fetch(\PDO::FETCH_ASSOC);
113
+		} catch (\Exception $e) {
114
+			echo $e->getMessage();
115
+		}
116
+		return '';
117
+	}
118
+
119
+	/**
120
+	 * Get data about speed of the application
121
+	 *
122
+	 * @returns array
123
+	 */
124
+	public function gatherSpeedData()
125
+	{
126
+		$elapsedTime = microtime(true) - $this->startTime;
127
+		$allowedTime = ini_get('max_execution_time');
128
+		return array(
129
+			'elapsed' => $elapsedTime,
130
+			'allowed' => $allowedTime
131
+		);
132
+	}
133
+
134
+	/**
135
+	 * Triggers end display of the profiling data
136
+	 *
137
+	 * @param Display $display
138
+	 * @param array   $profiledQueries
139
+	 */
140
+	public function display(Display $display, array $profiledQueries = array())
141
+	{
142
+		$display->setConsole($this->console);
143
+		$display->setFileData($this->gatherFileData());
144
+		$display->setMemoryData($this->gatherMemoryData());
145
+		$display->setQueryData($this->gatherQueryData($profiledQueries));
146
+		$display->setSpeedData($this->gatherSpeedData());
147
+
148
+		$display();
149
+	}
150 150
 }
Please login to merge, or discard this patch.
tests/unit/PhpQuickProfilerTest.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,18 +6,18 @@
 block discarded – undo
6 6
 class PhpQuickProfilerTest extends PHPUnit_Framework_TestCase
7 7
 {
8 8
 
9
-    public function __construct()
10
-    {
11
-    }
9
+	public function __construct()
10
+	{
11
+	}
12 12
 
13
-    public function testConstruct()
14
-    {
15
-        $console = new Console();
16
-        $startTime = microtime(true);
13
+	public function testConstruct()
14
+	{
15
+		$console = new Console();
16
+		$startTime = microtime(true);
17 17
 
18
-        $profiler = new PhpQuickProfiler($console, null, $startTime);
18
+		$profiler = new PhpQuickProfiler($console, null, $startTime);
19 19
 
20
-        $this->assertAttributeSame($console, 'console', $profiler);
21
-        $this->assertAttributeEquals($startTime, 'startTime', $profiler);
22
-    }
20
+		$this->assertAttributeSame($console, 'console', $profiler);
21
+		$this->assertAttributeEquals($startTime, 'startTime', $profiler);
22
+	}
23 23
 }
Please login to merge, or discard this patch.
asset/display.tpl.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,8 @@  discard block
 block discarded – undo
28 28
     <div id="pqp-console" class="pqp-box">
29 29
     <?php if (count($output['console']) == 0): ?>
30 30
       <h3>This panel has no log items.</h3>
31
-    <?php else: ?>
31
+    <?php else {
32
+	: ?>
32 33
       <table class="side" cellspacing="0">
33 34
         <tr>
34 35
           <td class="alt1">
@@ -64,7 +65,9 @@  discard block
 block discarded – undo
64 65
               <pre><?php echo $log['data'] ?></pre>
65 66
               <?php if (!empty($log['data_type'])): ?>
66 67
               <em><?php echo $log['data_type'] ?></em>
67
-              <?php endif; ?>
68
+              <?php endif;
69
+}
70
+?>
68 71
               <?php echo $log['name'] ?>
69 72
             </div>
70 73
           <?php elseif ($log['type'] == 'speed'): ?>
Please login to merge, or discard this patch.
src/Display.php 2 patches
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -14,222 +14,222 @@
 block discarded – undo
14 14
 class Display
15 15
 {
16 16
 
17
-    /** @var  array */
18
-    protected $defaults = array(
19
-        'script_path' => 'asset/script.js',
20
-        'style_path'  => 'asset/style.css'
21
-    );
22
-
23
-    /** @var  array */
24
-    protected $options;
25
-
26
-    /** @var  array */
27
-    protected $output;
28
-
29
-    /**
30
-     * @param array $options
31
-     */
32
-    public function __construct(array $options = array())
33
-    {
34
-        $options = array_intersect_key($options, $this->defaults);
35
-        $this->options = array_replace($this->defaults, $options);
36
-    }
37
-
38
-    public function setConsole(Console $console)
39
-    {
40
-        $console_data = array(
41
-            'messages' => array(),
42
-            'count'    => array(
43
-                'log'    => 0,
44
-                'memory' => 0,
45
-                'error'  => 0,
46
-                'speed'  => 0
47
-            )
48
-        );
49
-        foreach ($console->getLogs() as $log) {
50
-            switch($log['type']) {
51
-                case 'log':
52
-                    $message = array(
53
-                        'data' => print_r($log['data'], true),
54
-                        'type' => 'log'
55
-                    );
56
-                    $console_data['count']['log']++;
57
-                    break;
58
-                case 'memory':
59
-                    $message = array(
60
-                        'name' => $log['name'],
61
-                        'data' => self::getReadableMemory($log['data']),
62
-                        'type' => 'memory'
63
-                    );
64
-                    if (!empty($log['data_type'])) {
65
-                        $message['data_type'] = $log['data_type'];
66
-                    }
67
-                    $console_data['count']['memory']++;
68
-                    break;
69
-                case 'error':
70
-                    $message = array(
71
-                        'data' => $log['data'],
72
-                        'file' => $log['file'],
73
-                        'line' => $log['line'],
74
-                        'type' => 'error'
75
-                    );
76
-                    $console_data['count']['error']++;
77
-                    break;
78
-                case 'speed':
79
-                    $elapsedTime = $log['data'] - $this->startTime;
80
-                    $message = array(
81
-                        'name' => $log['name'],
82
-                        'data' => self::getReadableTime($elapsedTime),
83
-                        'type' => 'speed'
84
-                    );
85
-                    $console_data['count']['speed']++;
86
-                    break;
87
-                default:
88
-                    $message = array(
89
-                        'data' => "Unrecognized console log type: {$log['type']}",
90
-                        'type' => 'error'
91
-                    );
92
-                    $console_data['count']['error']++;
93
-                    break;
94
-            }
95
-            array_push($console_data['messages'], $message);
96
-        }
97
-        $this->output['console'] = $console_data;
98
-    }
99
-
100
-    /**
101
-     * Sets file data
102
-     *
103
-     * @param array $data
104
-     */
105
-    public function setFileData(array $data)
106
-    {
107
-        $fileData = array(
108
-            'fileList'   => array(),
109
-            'fileTotals' => array(
110
-                'count'   => count($data),
111
-                'size'    => 0,
112
-                'largest' => 0
113
-            )
114
-        );
115
-
116
-        foreach ($data as $file) {
117
-            array_push($fileData['fileList'], array(
118
-                'name' => $file['name'],
119
-                'size' => self::getReadableMemory($file['size'])
120
-            ));
121
-
122
-            $fileData['fileTotals']['size'] += $file['size'];
123
-            if ($file['size'] > $fileData['fileTotals']['largest']) {
124
-                $fileData['fileTotals']['largest'] = $file['size'];
125
-            }
126
-        }
127
-
128
-        $fileData['fileTotals']['size'] = self::getReadableMemory($fileData['fileTotals']['size']);
129
-        $fileData['fileTotals']['largest'] = self::getReadableMemory($fileData['fileTotals']['largest']);
130
-
131
-        $this->output['files'] = $fileData['fileList'];
132
-        $this->output['fileTotals'] = $fileData['fileTotals'];
133
-    }
134
-
135
-    /**
136
-     * Sets memory data
137
-     *
138
-     * @param array $data
139
-     */
140
-    public function setMemoryData(array $data)
141
-    {
142
-        $this->output['memory'] = array(
143
-            'used'    => self::getReadableMemory($data['used']),
144
-            'allowed' => $data['allowed']
145
-        );
146
-    }
147
-
148
-    public function setQueryData(array $data)
149
-    {
150
-        $queryData = array(
151
-            'queries'     => array(),
152
-            'queryTotals' => array(
153
-                'count'   => count($data),
154
-                'time'    => 0,
155
-            )
156
-        );
157
-
158
-        foreach ($data as $query) {
159
-            array_push($queryData['queries'], array(
160
-                'sql'     => $query['sql'],
161
-                'explain' => $query['explain'],
162
-                'time'    => self::getReadableTime($query['time'])
163
-            ));
164
-
165
-            $queryData['queryTotals']['time'] += $query['time'];
166
-        }
167
-
168
-        $queryData['queryTotals']['time'] = self::getReadableTime($queryData['queryTotals']['time']);
169
-
170
-        $this->output['queries'] = $queryData['queries'];
171
-        $this->output['queryTotals'] = $queryData['queryTotals'];
172
-    }
173
-
174
-    /**
175
-     * Sets speed data
176
-     *
177
-     * @param array $data
178
-     */
179
-    public function setSpeedData(array $data)
180
-    {
181
-        $this->output['speed'] = array(
182
-            'elapsed' => self::getReadableTime($data['elapsed']),
183
-            'allowed' => self::getReadableTime($data['allowed'], 0)
184
-        );
185
-    }
186
-
187
-    /**
188
-     * Static formatter for human-readable time
189
-     * Only handles time up to 60 minutes gracefully
190
-     *
191
-     * @param double  $time
192
-     * @param integer $decimals
193
-     * @return string
194
-     */
195
-    public static function getReadableTime($time, $decimals = 3)
196
-    {
197
-        $unit = 's';
198
-        if ($time < 1) {
199
-            $time *= 1000;
200
-            $unit = 'ms';
201
-        } else if ($time > 60) {
202
-            $time /= 60;
203
-            $unit = 'm';
204
-        }
205
-        $time = number_format($time, $decimals);
206
-        return "{$time} {$unit}";
207
-    }
208
-
209
-    /**
210
-     * Static formatter for human-readable memory
211
-     *
212
-     * @param double  $size
213
-     * @param integer $decimals
214
-     */
215
-    public static function getReadableMemory($size, $decimals = 2)
216
-    {
217
-        $unitOptions = array('b', 'k', 'M', 'G');
218
-
219
-        $base = log($size, 1024);
220
-
221
-        $memory = round(pow(1024, $base - floor($base)), $decimals);
222
-        $unit = $unitOptions[floor($base)];
223
-        return "{$memory} {$unit}";
224
-    }
17
+	/** @var  array */
18
+	protected $defaults = array(
19
+		'script_path' => 'asset/script.js',
20
+		'style_path'  => 'asset/style.css'
21
+	);
22
+
23
+	/** @var  array */
24
+	protected $options;
25
+
26
+	/** @var  array */
27
+	protected $output;
28
+
29
+	/**
30
+	 * @param array $options
31
+	 */
32
+	public function __construct(array $options = array())
33
+	{
34
+		$options = array_intersect_key($options, $this->defaults);
35
+		$this->options = array_replace($this->defaults, $options);
36
+	}
37
+
38
+	public function setConsole(Console $console)
39
+	{
40
+		$console_data = array(
41
+			'messages' => array(),
42
+			'count'    => array(
43
+				'log'    => 0,
44
+				'memory' => 0,
45
+				'error'  => 0,
46
+				'speed'  => 0
47
+			)
48
+		);
49
+		foreach ($console->getLogs() as $log) {
50
+			switch($log['type']) {
51
+				case 'log':
52
+					$message = array(
53
+						'data' => print_r($log['data'], true),
54
+						'type' => 'log'
55
+					);
56
+					$console_data['count']['log']++;
57
+					break;
58
+				case 'memory':
59
+					$message = array(
60
+						'name' => $log['name'],
61
+						'data' => self::getReadableMemory($log['data']),
62
+						'type' => 'memory'
63
+					);
64
+					if (!empty($log['data_type'])) {
65
+						$message['data_type'] = $log['data_type'];
66
+					}
67
+					$console_data['count']['memory']++;
68
+					break;
69
+				case 'error':
70
+					$message = array(
71
+						'data' => $log['data'],
72
+						'file' => $log['file'],
73
+						'line' => $log['line'],
74
+						'type' => 'error'
75
+					);
76
+					$console_data['count']['error']++;
77
+					break;
78
+				case 'speed':
79
+					$elapsedTime = $log['data'] - $this->startTime;
80
+					$message = array(
81
+						'name' => $log['name'],
82
+						'data' => self::getReadableTime($elapsedTime),
83
+						'type' => 'speed'
84
+					);
85
+					$console_data['count']['speed']++;
86
+					break;
87
+				default:
88
+					$message = array(
89
+						'data' => "Unrecognized console log type: {$log['type']}",
90
+						'type' => 'error'
91
+					);
92
+					$console_data['count']['error']++;
93
+					break;
94
+			}
95
+			array_push($console_data['messages'], $message);
96
+		}
97
+		$this->output['console'] = $console_data;
98
+	}
99
+
100
+	/**
101
+	 * Sets file data
102
+	 *
103
+	 * @param array $data
104
+	 */
105
+	public function setFileData(array $data)
106
+	{
107
+		$fileData = array(
108
+			'fileList'   => array(),
109
+			'fileTotals' => array(
110
+				'count'   => count($data),
111
+				'size'    => 0,
112
+				'largest' => 0
113
+			)
114
+		);
115
+
116
+		foreach ($data as $file) {
117
+			array_push($fileData['fileList'], array(
118
+				'name' => $file['name'],
119
+				'size' => self::getReadableMemory($file['size'])
120
+			));
121
+
122
+			$fileData['fileTotals']['size'] += $file['size'];
123
+			if ($file['size'] > $fileData['fileTotals']['largest']) {
124
+				$fileData['fileTotals']['largest'] = $file['size'];
125
+			}
126
+		}
127
+
128
+		$fileData['fileTotals']['size'] = self::getReadableMemory($fileData['fileTotals']['size']);
129
+		$fileData['fileTotals']['largest'] = self::getReadableMemory($fileData['fileTotals']['largest']);
130
+
131
+		$this->output['files'] = $fileData['fileList'];
132
+		$this->output['fileTotals'] = $fileData['fileTotals'];
133
+	}
134
+
135
+	/**
136
+	 * Sets memory data
137
+	 *
138
+	 * @param array $data
139
+	 */
140
+	public function setMemoryData(array $data)
141
+	{
142
+		$this->output['memory'] = array(
143
+			'used'    => self::getReadableMemory($data['used']),
144
+			'allowed' => $data['allowed']
145
+		);
146
+	}
147
+
148
+	public function setQueryData(array $data)
149
+	{
150
+		$queryData = array(
151
+			'queries'     => array(),
152
+			'queryTotals' => array(
153
+				'count'   => count($data),
154
+				'time'    => 0,
155
+			)
156
+		);
157
+
158
+		foreach ($data as $query) {
159
+			array_push($queryData['queries'], array(
160
+				'sql'     => $query['sql'],
161
+				'explain' => $query['explain'],
162
+				'time'    => self::getReadableTime($query['time'])
163
+			));
164
+
165
+			$queryData['queryTotals']['time'] += $query['time'];
166
+		}
167
+
168
+		$queryData['queryTotals']['time'] = self::getReadableTime($queryData['queryTotals']['time']);
169
+
170
+		$this->output['queries'] = $queryData['queries'];
171
+		$this->output['queryTotals'] = $queryData['queryTotals'];
172
+	}
173
+
174
+	/**
175
+	 * Sets speed data
176
+	 *
177
+	 * @param array $data
178
+	 */
179
+	public function setSpeedData(array $data)
180
+	{
181
+		$this->output['speed'] = array(
182
+			'elapsed' => self::getReadableTime($data['elapsed']),
183
+			'allowed' => self::getReadableTime($data['allowed'], 0)
184
+		);
185
+	}
186
+
187
+	/**
188
+	 * Static formatter for human-readable time
189
+	 * Only handles time up to 60 minutes gracefully
190
+	 *
191
+	 * @param double  $time
192
+	 * @param integer $decimals
193
+	 * @return string
194
+	 */
195
+	public static function getReadableTime($time, $decimals = 3)
196
+	{
197
+		$unit = 's';
198
+		if ($time < 1) {
199
+			$time *= 1000;
200
+			$unit = 'ms';
201
+		} else if ($time > 60) {
202
+			$time /= 60;
203
+			$unit = 'm';
204
+		}
205
+		$time = number_format($time, $decimals);
206
+		return "{$time} {$unit}";
207
+	}
208
+
209
+	/**
210
+	 * Static formatter for human-readable memory
211
+	 *
212
+	 * @param double  $size
213
+	 * @param integer $decimals
214
+	 */
215
+	public static function getReadableMemory($size, $decimals = 2)
216
+	{
217
+		$unitOptions = array('b', 'k', 'M', 'G');
218
+
219
+		$base = log($size, 1024);
220
+
221
+		$memory = round(pow(1024, $base - floor($base)), $decimals);
222
+		$unit = $unitOptions[floor($base)];
223
+		return "{$memory} {$unit}";
224
+	}
225 225
  
226
-    public function __invoke()
227
-    {
228
-        $output = $this->output;
229
-        // todo is this really the best way to load these?
230
-        $styles = file_get_contents(__DIR__ . "./../{$this->options['style_path']}");
231
-        $script = file_get_contents(__DIR__ . "./../{$this->options['script_path']}");
232
-
233
-        require_once __DIR__ .'/../asset/display.tpl.php';
234
-    }
226
+	public function __invoke()
227
+	{
228
+		$output = $this->output;
229
+		// todo is this really the best way to load these?
230
+		$styles = file_get_contents(__DIR__ . "./../{$this->options['style_path']}");
231
+		$script = file_get_contents(__DIR__ . "./../{$this->options['script_path']}");
232
+
233
+		require_once __DIR__ .'/../asset/display.tpl.php';
234
+	}
235 235
 }	
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             )
48 48
         );
49 49
         foreach ($console->getLogs() as $log) {
50
-            switch($log['type']) {
50
+            switch ($log['type']) {
51 51
                 case 'log':
52 52
                     $message = array(
53 53
                         'data' => print_r($log['data'], true),
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
     {
228 228
         $output = $this->output;
229 229
         // todo is this really the best way to load these?
230
-        $styles = file_get_contents(__DIR__ . "./../{$this->options['style_path']}");
231
-        $script = file_get_contents(__DIR__ . "./../{$this->options['script_path']}");
230
+        $styles = file_get_contents(__DIR__."./../{$this->options['style_path']}");
231
+        $script = file_get_contents(__DIR__."./../{$this->options['script_path']}");
232 232
 
233
-        require_once __DIR__ .'/../asset/display.tpl.php';
233
+        require_once __DIR__.'/../asset/display.tpl.php';
234 234
     }
235 235
 }	
Please login to merge, or discard this patch.