Skip to content

Commit 056bd60

Browse files
igorsantos07barryvdh
authored andcommitted
Improving some PHPDoc types and array notation for readability (php-debugbar#404)
1 parent 3169ed5 commit 056bd60

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

src/DebugBar/DataCollector/PDO/TraceablePDO.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class TraceablePDO extends PDO
1414
/** @var PDO */
1515
protected $pdo;
1616

17-
/** @var array */
18-
protected $executedStatements = array();
17+
/** @var TracedStatement[] */
18+
protected $executedStatements = [];
1919

2020
public function __construct(PDO $pdo)
2121
{
2222
$this->pdo = $pdo;
23-
$this->pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('DebugBar\DataCollector\PDO\TraceablePDOStatement', array($this)));
23+
$this->pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, [TraceablePDOStatement::class, [$this]]);
2424
}
2525

2626
/**
@@ -130,7 +130,7 @@ public function lastInsertId($name = null)
130130
* PDO::prepare returns a PDOStatement object. If the database server cannot successfully prepare
131131
* the statement, PDO::prepare returns FALSE or emits PDOException (depending on error handling).
132132
*/
133-
public function prepare($statement, $driver_options = array())
133+
public function prepare($statement, $driver_options = [])
134134
{
135135
return $this->pdo->prepare($statement, $driver_options);
136136
}
@@ -202,7 +202,7 @@ protected function profileCall($method, $sql, array $args)
202202

203203
$ex = null;
204204
try {
205-
$result = call_user_func_array(array($this->pdo, $method), $args);
205+
$result = $this->__call($method, $args);
206206
} catch (PDOException $e) {
207207
$ex = $e;
208208
}
@@ -264,7 +264,7 @@ public function getPeakMemoryUsage()
264264
/**
265265
* Returns the list of executed statements as TracedStatement objects
266266
*
267-
* @return array
267+
* @return TracedStatement[]
268268
*/
269269
public function getExecutedStatements()
270270
{
@@ -274,7 +274,7 @@ public function getExecutedStatements()
274274
/**
275275
* Returns the list of failed statements
276276
*
277-
* @return array
277+
* @return TracedStatement[]
278278
*/
279279
public function getFailedExecutedStatements()
280280
{
@@ -306,6 +306,6 @@ public function __set($name, $value)
306306
*/
307307
public function __call($name, $args)
308308
{
309-
return call_user_func_array(array($this->pdo, $name), $args);
309+
return call_user_func_array([$this->pdo, $name], $args);
310310
}
311311
}

src/DebugBar/DataCollector/PDO/TraceablePDOStatement.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TraceablePDOStatement extends PDOStatement
1515
protected $pdo;
1616

1717
/** @var array */
18-
protected $boundParameters = array();
18+
protected $boundParameters = [];
1919

2020
/**
2121
* TraceablePDOStatement constructor.
@@ -42,8 +42,8 @@ protected function __construct(TraceablePDO $pdo)
4242
public function bindColumn($column, &$param, $type = null, $maxlen = null, $driverdata = null)
4343
{
4444
$this->boundParameters[$column] = $param;
45-
$args = array_merge(array($column, &$param), array_slice(func_get_args(), 2));
46-
return call_user_func_array(array("parent", 'bindColumn'), $args);
45+
$args = array_merge([$column, &$param], array_slice(func_get_args(), 2));
46+
return call_user_func_array(['parent', 'bindColumn'], $args);
4747
}
4848

4949
/**
@@ -64,8 +64,8 @@ public function bindColumn($column, &$param, $type = null, $maxlen = null, $driv
6464
public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null)
6565
{
6666
$this->boundParameters[$parameter] = $variable;
67-
$args = array_merge(array($parameter, &$variable), array_slice(func_get_args(), 2));
68-
return call_user_func_array(array("parent", 'bindParam'), $args);
67+
$args = array_merge([$parameter, &$variable], array_slice(func_get_args(), 2));
68+
return call_user_func_array(['parent', 'bindParam'], $args);
6969
}
7070

7171
/**
@@ -83,7 +83,7 @@ public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $
8383
public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
8484
{
8585
$this->boundParameters[$parameter] = $value;
86-
return call_user_func_array(array("parent", 'bindValue'), func_get_args());
86+
return call_user_func_array(['parent', 'bindValue'], func_get_args());
8787
}
8888

8989
/**
@@ -93,6 +93,7 @@ public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
9393
* @param array $input_parameters [optional] An array of values with as many elements as there
9494
* are bound parameters in the SQL statement being executed. All values are treated as
9595
* PDO::PARAM_STR.
96+
* @throws PDOException
9697
* @return bool TRUE on success or FALSE on failure.
9798
*/
9899
public function execute($input_parameters = null)

src/DebugBar/DataCollector/PDO/TracedStatement.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class TracedStatement
3232
* @param array $params
3333
* @param string $preparedId
3434
*/
35-
public function __construct($sql, array $params = array(), $preparedId = null)
35+
public function __construct($sql, array $params = [], $preparedId = null)
3636
{
3737
$this->sql = $sql;
3838
$this->parameters = $this->checkParameters($params);
@@ -52,8 +52,8 @@ public function start($startTime = null, $startMemory = null)
5252
/**
5353
* @param \Exception|null $exception
5454
* @param int $rowCount
55-
* @param null $endTime
56-
* @param null $endMemory
55+
* @param float $endTime
56+
* @param int $endMemory
5757
*/
5858
public function end(\Exception $exception = null, $rowCount = 0, $endTime = null, $endMemory = null)
5959
{
@@ -68,8 +68,8 @@ public function end(\Exception $exception = null, $rowCount = 0, $endTime = null
6868
/**
6969
* Check parameters for illegal (non UTF-8) strings, like Binary data.
7070
*
71-
* @param $params
72-
* @return mixed
71+
* @param array $params
72+
* @return array
7373
*/
7474
public function checkParameters($params)
7575
{
@@ -82,7 +82,7 @@ public function checkParameters($params)
8282
}
8383

8484
/**
85-
* Returns the SQL string used for the query
85+
* Returns the SQL string used for the query, without filled parameters
8686
*
8787
* @return string
8888
*/
@@ -108,7 +108,7 @@ public function getSqlWithParams($quotationChar = '<>')
108108

109109
$sql = $this->sql;
110110

111-
$cleanBackRefCharMap = array('%'=>'%%', '$'=>'$%', '\\'=>'\\%');
111+
$cleanBackRefCharMap = ['%' => '%%', '$' => '$%', '\\' => '\\%'];
112112

113113
foreach ($this->parameters as $k => $v) {
114114

@@ -150,7 +150,7 @@ public function getRowCount()
150150
*/
151151
public function getParameters()
152152
{
153-
$params = array();
153+
$params = [];
154154
foreach ($this->parameters as $name => $param) {
155155
$params[$name] = htmlentities($param, ENT_QUOTES, 'UTF-8', false);
156156
}
@@ -178,41 +178,41 @@ public function isPrepared()
178178
}
179179

180180
/**
181-
* @return mixed
181+
* @return float
182182
*/
183183
public function getStartTime()
184184
{
185185
return $this->startTime;
186186
}
187187

188188
/**
189-
* @return mixed
189+
* @return float
190190
*/
191191
public function getEndTime()
192192
{
193193
return $this->endTime;
194194
}
195195

196196
/**
197-
* Returns the duration in seconds of the execution
197+
* Returns the duration in seconds + microseconds of the execution
198198
*
199-
* @return int
199+
* @return float
200200
*/
201201
public function getDuration()
202202
{
203203
return $this->duration;
204204
}
205205

206206
/**
207-
* @return mixed
207+
* @return int
208208
*/
209209
public function getStartMemory()
210210
{
211211
return $this->startMemory;
212212
}
213213

214214
/**
215-
* @return mixed
215+
* @return int
216216
*/
217217
public function getEndMemory()
218218
{
@@ -252,7 +252,7 @@ public function getException()
252252
/**
253253
* Returns the exception's code
254254
*
255-
* @return string
255+
* @return int|string
256256
*/
257257
public function getErrorCode()
258258
{

0 commit comments

Comments
 (0)