Completed
Push — master ( 28ba71...f9b271 )
by Jacob
02:20
created
src/displayPqp.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@
 block discarded – undo
20 20
 class displayPqp
21 21
 {
22 22
 
23
-    public function __invoke($output)
24
-    {
23
+	public function __invoke($output)
24
+	{
25 25
 	
26 26
 $css = file_get_contents(__DIR__ . '/../css/pQp.css');
27 27
 		
Please login to merge, or discard this patch.
src/PhpQuickProfiler.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -15,78 +15,78 @@  discard block
 block discarded – undo
15 15
 class PhpQuickProfiler
16 16
 {
17 17
 
18
-    /** @var  Particletree\Pqp\Console */
19
-    protected $console;
18
+	/** @var  Particletree\Pqp\Console */
19
+	protected $console;
20 20
 
21
-    /** @var  integer */
22
-    protected $startTime;
21
+	/** @var  integer */
22
+	protected $startTime;
23 23
 
24
-    /**
25
-     * @param Particletree\Pqp\Console $console
26
-     * @param integer                  $startTime
27
-     */
28
-    public function __construct(Console $console, $startTime = null)
29
-    {
30
-        $this->console = $console;
24
+	/**
25
+	 * @param Particletree\Pqp\Console $console
26
+	 * @param integer                  $startTime
27
+	 */
28
+	public function __construct(Console $console, $startTime = null)
29
+	{
30
+		$this->console = $console;
31 31
 
32
-        if (is_null($startTime)) {
33
-            $startTime = microtime(true);
34
-        }
35
-        $this->startTime = $startTime;
36
-    }
32
+		if (is_null($startTime)) {
33
+			$startTime = microtime(true);
34
+		}
35
+		$this->startTime = $startTime;
36
+	}
37 37
  
38
-    /**
39
-     * Formats the logs from the console
40
-     *
41
-     * @return array
42
-     */
43
-    protected function gatherConsoleData()
44
-    {
45
-    $console = array(
46
-      'messages' => array(),
47
-      'totals' => array(
48
-        'log' => 0,
49
-        'memory' => 0,
50
-        'error' => 0,
51
-        'speed' => 0
52
-      ));
53
-    $logs = $this->console->getLogs();
54
-      foreach($logs as $log) {
55
-        if($log['type'] == 'log') {
56
-          $message = array(
57
-            'data' => print_r($log['data'], true),
58
-            'type' => 'log'
59
-          );
60
-          $console['totals']['log']++;
61
-        }
62
-        elseif($log['type'] == 'memory') {
63
-          $message = array(
64
-            'name'    => $log['name'],
65
-            'data_type'    => $log['data_type'],
66
-            'data'   => $this->getReadableFileSize($log['data']),
67
-            'type' => 'memory'
68
-          );
69
-          $console['totals']['memory']++;
70
-        }
71
-        elseif($log['type'] == 'speed') {
72
-          $message = array(
73
-            'name' => $log['name'],
74
-            'data'    => $this->getReadableTime(($log['data'] - $this->startTime) * 1000),
75
-            'type' => 'speed'
76
-          );
77
-          $console['totals']['speed']++;
78
-        } else {
79
-          $message = array(
80
-            'data' => $log['data'],
81
-            'type' => 'error',
82
-            'file' => $log['file'],
83
-            'line' => $log['line']
84
-          );
85
-          $console['totals']['error']++;
86
-        }
87
-        array_push($console['messages'], $message);
88
-      }
89
-    $this->output['logs'] = array('console' => $console);
38
+	/**
39
+	 * Formats the logs from the console
40
+	 *
41
+	 * @return array
42
+	 */
43
+	protected function gatherConsoleData()
44
+	{
45
+	$console = array(
46
+	  'messages' => array(),
47
+	  'totals' => array(
48
+		'log' => 0,
49
+		'memory' => 0,
50
+		'error' => 0,
51
+		'speed' => 0
52
+	  ));
53
+	$logs = $this->console->getLogs();
54
+	  foreach($logs as $log) {
55
+		if($log['type'] == 'log') {
56
+		  $message = array(
57
+			'data' => print_r($log['data'], true),
58
+			'type' => 'log'
59
+		  );
60
+		  $console['totals']['log']++;
61
+		}
62
+		elseif($log['type'] == 'memory') {
63
+		  $message = array(
64
+			'name'    => $log['name'],
65
+			'data_type'    => $log['data_type'],
66
+			'data'   => $this->getReadableFileSize($log['data']),
67
+			'type' => 'memory'
68
+		  );
69
+		  $console['totals']['memory']++;
70
+		}
71
+		elseif($log['type'] == 'speed') {
72
+		  $message = array(
73
+			'name' => $log['name'],
74
+			'data'    => $this->getReadableTime(($log['data'] - $this->startTime) * 1000),
75
+			'type' => 'speed'
76
+		  );
77
+		  $console['totals']['speed']++;
78
+		} else {
79
+		  $message = array(
80
+			'data' => $log['data'],
81
+			'type' => 'error',
82
+			'file' => $log['file'],
83
+			'line' => $log['line']
84
+		  );
85
+		  $console['totals']['error']++;
86
+		}
87
+		array_push($console['messages'], $message);
88
+	  }
89
+	$this->output['logs'] = array('console' => $console);
90 90
   }
91 91
   
92 92
   /*-------------------------------------------
@@ -94,28 +94,28 @@  discard block
 block discarded – undo
94 94
   -------------------------------------------*/
95 95
   
96 96
   public function gatherFileData() {
97
-    $files = get_included_files();
98
-    $fileList = array();
99
-    $fileTotals = array(
100
-      "count" => count($files),
101
-      "size" => 0,
102
-      "largest" => 0,
103
-    );
97
+	$files = get_included_files();
98
+	$fileList = array();
99
+	$fileTotals = array(
100
+	  "count" => count($files),
101
+	  "size" => 0,
102
+	  "largest" => 0,
103
+	);
104 104
 
105
-    foreach($files as $file) {
106
-      $size = filesize($file);
107
-      $fileList[] = array(
108
-          'name' => $file,
109
-          'size' => $this->getReadableFileSize($size)
110
-        );
111
-      $fileTotals['size'] += $size;
112
-      if($size > $fileTotals['largest']) $fileTotals['largest'] = $size;
113
-    }
105
+	foreach($files as $file) {
106
+	  $size = filesize($file);
107
+	  $fileList[] = array(
108
+		  'name' => $file,
109
+		  'size' => $this->getReadableFileSize($size)
110
+		);
111
+	  $fileTotals['size'] += $size;
112
+	  if($size > $fileTotals['largest']) $fileTotals['largest'] = $size;
113
+	}
114 114
     
115
-    $fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']);
116
-    $fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']);
117
-    $this->output['files'] = $fileList;
118
-    $this->output['fileTotals'] = $fileTotals;
115
+	$fileTotals['size'] = $this->getReadableFileSize($fileTotals['size']);
116
+	$fileTotals['largest'] = $this->getReadableFileSize($fileTotals['largest']);
117
+	$this->output['files'] = $fileList;
118
+	$this->output['fileTotals'] = $fileTotals;
119 119
   }
120 120
   
121 121
   /*-------------------------------------------
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
   -------------------------------------------*/
124 124
   
125 125
   public function gatherMemoryData() {
126
-    $memoryTotals = array();
127
-    $memoryTotals['used'] = $this->getReadableFileSize(memory_get_peak_usage());
128
-    $memoryTotals['total'] = ini_get("memory_limit");
129
-    $this->output['memoryTotals'] = $memoryTotals;
126
+	$memoryTotals = array();
127
+	$memoryTotals['used'] = $this->getReadableFileSize(memory_get_peak_usage());
128
+	$memoryTotals['total'] = ini_get("memory_limit");
129
+	$this->output['memoryTotals'] = $memoryTotals;
130 130
   }
131 131
   
132 132
   /*--------------------------------------------------------
@@ -134,24 +134,24 @@  discard block
 block discarded – undo
134 134
   ----------------------------------------------------------*/
135 135
   
136 136
   public function gatherQueryData() {
137
-    $queryTotals = array();
138
-    $queryTotals['count'] = 0;
139
-    $queryTotals['time'] = 0;
140
-    $queries = array();
137
+	$queryTotals = array();
138
+	$queryTotals['count'] = 0;
139
+	$queryTotals['time'] = 0;
140
+	$queries = array();
141 141
     
142
-    if($this->db != '') {
143
-      $queryTotals['count'] += $this->db->queryCount;
144
-      foreach($this->db->queries as $query) {
145
-        $query = $this->attemptToExplainQuery($query);
146
-        $queryTotals['time'] += $query['time'];
147
-        $query['time'] = $this->getReadableTime($query['time']);
148
-        $queries[] = $query;
149
-      }
150
-    }
142
+	if($this->db != '') {
143
+	  $queryTotals['count'] += $this->db->queryCount;
144
+	  foreach($this->db->queries as $query) {
145
+		$query = $this->attemptToExplainQuery($query);
146
+		$queryTotals['time'] += $query['time'];
147
+		$query['time'] = $this->getReadableTime($query['time']);
148
+		$queries[] = $query;
149
+	  }
150
+	}
151 151
     
152
-    $queryTotals['time'] = $this->getReadableTime($queryTotals['time']);
153
-    $this->output['queries'] = $queries;
154
-    $this->output['queryTotals'] = $queryTotals;
152
+	$queryTotals['time'] = $this->getReadableTime($queryTotals['time']);
153
+	$this->output['queries'] = $queries;
154
+	$this->output['queryTotals'] = $queryTotals;
155 155
   }
156 156
   
157 157
   /*--------------------------------------------------------
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
   ----------------------------------------------------------*/
160 160
   
161 161
   function attemptToExplainQuery($query) {
162
-    try {
163
-      $sql = 'EXPLAIN '.$query['sql'];
164
-      $rs = $this->db->query($sql);
165
-    }
166
-    catch(Exception $e) {}
167
-    if($rs) {
168
-      $row = mysql_fetch_array($rs, MYSQL_ASSOC);
169
-      $query['explain'] = $row;
170
-    }
171
-    return $query;
162
+	try {
163
+	  $sql = 'EXPLAIN '.$query['sql'];
164
+	  $rs = $this->db->query($sql);
165
+	}
166
+	catch(Exception $e) {}
167
+	if($rs) {
168
+	  $row = mysql_fetch_array($rs, MYSQL_ASSOC);
169
+	  $query['explain'] = $row;
170
+	}
171
+	return $query;
172 172
   }
173 173
   
174 174
   /*-------------------------------------------
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
   -------------------------------------------*/
177 177
   
178 178
   public function gatherSpeedData() {
179
-    $speedTotals = array();
180
-    $speedTotals['total'] = $this->getReadableTime((microtime(true) - $this->startTime)*1000);
181
-    $speedTotals['allowed'] = ini_get("max_execution_time");
182
-    $this->output['speedTotals'] = $speedTotals;
179
+	$speedTotals = array();
180
+	$speedTotals['total'] = $this->getReadableTime((microtime(true) - $this->startTime)*1000);
181
+	$speedTotals['allowed'] = ini_get("max_execution_time");
182
+	$this->output['speedTotals'] = $speedTotals;
183 183
   }
184 184
   
185 185
   /*-------------------------------------------
@@ -187,35 +187,35 @@  discard block
 block discarded – undo
187 187
   -------------------------------------------*/
188 188
   
189 189
   public function getReadableFileSize($size, $retstring = null) {
190
-          // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php
191
-         $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
190
+		  // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php
191
+		 $sizes = array('bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
192 192
 
193
-         if ($retstring === null) { $retstring = '%01.2f %s'; }
193
+		 if ($retstring === null) { $retstring = '%01.2f %s'; }
194 194
 
195
-    $lastsizestring = end($sizes);
195
+	$lastsizestring = end($sizes);
196 196
 
197
-    foreach ($sizes as $sizestring) {
198
-          if ($size < 1024) { break; }
199
-             if ($sizestring != $lastsizestring) { $size /= 1024; }
200
-         }
201
-         if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional
202
-         return sprintf($retstring, $size, $sizestring);
197
+	foreach ($sizes as $sizestring) {
198
+		  if ($size < 1024) { break; }
199
+			 if ($sizestring != $lastsizestring) { $size /= 1024; }
200
+		 }
201
+		 if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional
202
+		 return sprintf($retstring, $size, $sizestring);
203 203
   }
204 204
   
205 205
   public function getReadableTime($time) {
206
-    $ret = $time;
207
-    $formatter = 0;
208
-    $formats = array('ms', 's', 'm');
209
-    if($time >= 1000 && $time < 60000) {
210
-      $formatter = 1;
211
-      $ret = ($time / 1000);
212
-    }
213
-    if($time >= 60000) {
214
-      $formatter = 2;
215
-      $ret = ($time / 1000) / 60;
216
-    }
217
-    $ret = number_format($ret,3,'.','') . ' ' . $formats[$formatter];
218
-    return $ret;
206
+	$ret = $time;
207
+	$formatter = 0;
208
+	$formats = array('ms', 's', 'm');
209
+	if($time >= 1000 && $time < 60000) {
210
+	  $formatter = 1;
211
+	  $ret = ($time / 1000);
212
+	}
213
+	if($time >= 60000) {
214
+	  $formatter = 2;
215
+	  $ret = ($time / 1000) / 60;
216
+	}
217
+	$ret = number_format($ret,3,'.','') . ' ' . $formats[$formatter];
218
+	return $ret;
219 219
   }
220 220
   
221 221
   /*---------------------------------------------------------
@@ -223,14 +223,14 @@  discard block
 block discarded – undo
223 223
   -----------------------------------------------------------*/
224 224
   
225 225
   public function display($db = '', $master_db = '') {
226
-    $this->db = $db;
227
-    $this->master_db = $master_db;
228
-    $this->gatherConsoleData();
229
-    $this->gatherFileData();
230
-    $this->gatherMemoryData();
231
-    $this->gatherQueryData();
232
-    $this->gatherSpeedData();
233
-    $display = new displayPqp();
234
-    $display($this->output);
226
+	$this->db = $db;
227
+	$this->master_db = $master_db;
228
+	$this->gatherConsoleData();
229
+	$this->gatherFileData();
230
+	$this->gatherMemoryData();
231
+	$this->gatherQueryData();
232
+	$this->gatherSpeedData();
233
+	$display = new displayPqp();
234
+	$display($this->output);
235 235
   }
236 236
 }
Please login to merge, or discard this patch.