Completed
Push — master ( 77243d...dac2cf )
by Jacob
02:14
created
src/Console.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -15,86 +15,86 @@
 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 = '')
43
-    {
44
-        $memory = memory_get_usage();
45
-        if (!is_null($object)) {
46
-            $memory = strlen(serialize($object));
47
-        }
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 = '')
43
+	{
44
+		$memory = memory_get_usage();
45
+		if (!is_null($object)) {
46
+			$memory = strlen(serialize($object));
47
+		}
48 48
 
49
-        array_push($this->store, array(
50
-            'name'      => $name,
51
-            'data'      => $memory,
52
-            'data_type' => gettype($object),
53
-            'type'      => 'memory'
54
-        ));
55
-    }
49
+		array_push($this->store, array(
50
+			'name'      => $name,
51
+			'data'      => $memory,
52
+			'data_type' => gettype($object),
53
+			'type'      => 'memory'
54
+		));
55
+	}
56 56
 
57
-    /**
58
-     * Logs exception with optional message override
59
-     *
60
-     * @param Exception $exception
61
-     * @param string    $message
62
-     */
63
-    public function logError(Exception $exception, $message = '')
64
-    {
65
-        if (empty($message)) {
66
-            $message = $exception->getMessage();
67
-        }
57
+	/**
58
+	 * Logs exception with optional message override
59
+	 *
60
+	 * @param Exception $exception
61
+	 * @param string    $message
62
+	 */
63
+	public function logError(Exception $exception, $message = '')
64
+	{
65
+		if (empty($message)) {
66
+			$message = $exception->getMessage();
67
+		}
68 68
 
69
-        array_push($this->store, array(
70
-            'data' => $message,
71
-            'file' => $exception->getFile(),
72
-            'line' => $exception->getLine(),
73
-            'type' => 'error'
74
-        ));
75
-    }
69
+		array_push($this->store, array(
70
+			'data' => $message,
71
+			'file' => $exception->getFile(),
72
+			'line' => $exception->getLine(),
73
+			'type' => 'error'
74
+		));
75
+	}
76 76
 
77
-    /**
78
-     * Logs current time with optional message
79
-     *
80
-     * @param string $name
81
-     */
82
-    public function logSpeed($name = 'Point in Time')
83
-    {
84
-        array_push($this->store, array(
85
-            'data' => microtime(true),
86
-            'name' => $name,
87
-            'type' => 'speed'
88
-        ));
89
-    }
77
+	/**
78
+	 * Logs current time with optional message
79
+	 *
80
+	 * @param string $name
81
+	 */
82
+	public function logSpeed($name = 'Point in Time')
83
+	{
84
+		array_push($this->store, array(
85
+			'data' => microtime(true),
86
+			'name' => $name,
87
+			'type' => 'speed'
88
+		));
89
+	}
90 90
 
91
-    /**
92
-     * Returns the collected logs
93
-     *
94
-     * @returns array
95
-     */
96
-    public function getLogs()
97
-    {
98
-        return $this->store;
99
-    }
91
+	/**
92
+	 * Returns the collected logs
93
+	 *
94
+	 * @returns array
95
+	 */
96
+	public function getLogs()
97
+	{
98
+		return $this->store;
99
+	}
100 100
 }
Please login to merge, or discard this patch.
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/PhpQuickProfiler.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -24,11 +24,11 @@  discard block
 block discarded – undo
24 24
   protected $console;
25 25
 	
26 26
 	public function __construct($console, $startTime = null) {
27
-    $this->console = $console;
27
+	$this->console = $console;
28 28
 
29
-    if (is_null($startTime)) {
30
-        $startTime = microtime(true);
31
-    }
29
+	if (is_null($startTime)) {
30
+		$startTime = microtime(true);
31
+	}
32 32
 
33 33
 		$this->startTime = $startTime;
34 34
 	}
@@ -38,49 +38,49 @@  discard block
 block discarded – undo
38 38
 	-------------------------------------------*/
39 39
 	
40 40
 	public function gatherConsoleData() {
41
-    $console = array(
42
-      'messages' => array(),
43
-      'totals' => array(
44
-        'log' => 0,
45
-        'memory' => 0,
46
-        'error' => 0,
47
-        'speed' => 0
48
-      ));
41
+	$console = array(
42
+	  'messages' => array(),
43
+	  'totals' => array(
44
+		'log' => 0,
45
+		'memory' => 0,
46
+		'error' => 0,
47
+		'speed' => 0
48
+	  ));
49 49
 		$logs = $this->console->getLogs();
50 50
 			foreach($logs as $log) {
51 51
 				if($log['type'] == 'log') {
52 52
 					$message = array(
53
-            'data' => print_r($log['data'], true),
54
-            'type' => 'log'
55
-          );
56
-          $console['totals']['log']++;
53
+			'data' => print_r($log['data'], true),
54
+			'type' => 'log'
55
+		  );
56
+		  $console['totals']['log']++;
57 57
 				}
58 58
 				elseif($log['type'] == 'memory') {
59 59
 					$message = array(
60
-            'name'    => $log['name'],
61
-            'data_type'    => $log['data_type'],
62
-            'data'   => $this->getReadableFileSize($log['data']),
63
-            'type' => 'memory'
64
-          );
65
-          $console['totals']['memory']++;
60
+			'name'    => $log['name'],
61
+			'data_type'    => $log['data_type'],
62
+			'data'   => $this->getReadableFileSize($log['data']),
63
+			'type' => 'memory'
64
+		  );
65
+		  $console['totals']['memory']++;
66 66
 				}
67 67
 				elseif($log['type'] == 'speed') {
68
-          $message = array(
69
-            'name' => $log['name'],
70
-            'data'    => $this->getReadableTime(($log['data'] - $this->startTime) * 1000),
71
-            'type' => 'speed'
72
-          );
73
-          $console['totals']['speed']++;
68
+		  $message = array(
69
+			'name' => $log['name'],
70
+			'data'    => $this->getReadableTime(($log['data'] - $this->startTime) * 1000),
71
+			'type' => 'speed'
72
+		  );
73
+		  $console['totals']['speed']++;
74 74
 				} else {
75
-          $message = array(
76
-            'data' => $log['data'],
77
-            'type' => 'error',
78
-            'file' => $log['file'],
79
-            'line' => $log['line']
80
-          );
81
-          $console['totals']['error']++;
82
-        }
83
-        array_push($console['messages'], $message);
75
+		  $message = array(
76
+			'data' => $log['data'],
77
+			'type' => 'error',
78
+			'file' => $log['file'],
79
+			'line' => $log['line']
80
+		  );
81
+		  $console['totals']['error']++;
82
+		}
83
+		array_push($console['messages'], $message);
84 84
 			}
85 85
 		$this->output['logs'] = array('console' => $console);
86 86
 	}
@@ -183,19 +183,19 @@  discard block
 block discarded – undo
183 183
 	-------------------------------------------*/
184 184
 	
185 185
 	public function getReadableFileSize($size, $retstring = null) {
186
-        	// adapted from code at http://aidanlister.com/repos/v/function.size_readable.php
187
-	       $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
186
+			// adapted from code at http://aidanlister.com/repos/v/function.size_readable.php
187
+		   $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
188 188
 
189
-	       if ($retstring === null) { $retstring = '%01.2f %s'; }
189
+		   if ($retstring === null) { $retstring = '%01.2f %s'; }
190 190
 
191 191
 		$lastsizestring = end($sizes);
192 192
 
193 193
 		foreach ($sizes as $sizestring) {
194
-	       	if ($size < 1024) { break; }
195
-	           if ($sizestring != $lastsizestring) { $size /= 1024; }
196
-	       }
197
-	       if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional
198
-	       return sprintf($retstring, $size, $sizestring);
194
+		   	if ($size < 1024) { break; }
195
+			   if ($sizestring != $lastsizestring) { $size /= 1024; }
196
+		   }
197
+		   if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional
198
+		   return sprintf($retstring, $size, $sizestring);
199 199
 	}
200 200
 	
201 201
 	public function getReadableTime($time) {
Please login to merge, or discard this patch.