Skip to content

Commit 1386fe5

Browse files
phpfuibarryvdh
andauthored
Php8 1 fixes (php-debugbar#497)
* PHP 8.1 warning fixes Added #[\ReturnTypeWillChange] or appropriate return values Typed parameters where appropriate * Fixing unit tests to run without warnings * Update to more reasonable versions of PHP and PHPUnit (was missing PHPUnit 8) * mb_check_encoding param 1 can not be null * Fix SeekingData class for 8.1 * Update tests to not polute the temp directory * Revert PHP contrant * Tabs to spaces * Use Symfony\Component\VarDumper\Cloner\Data\SeekingData instead of local backported version Avoids Fatal error: Declaration of DebugBar\DataFormatter\VarDumper\SeekingData::seek($key) must be compatible with Symfony\Component\VarDumper\Cloner\Data::seek(string|int $key): ?static Co-authored-by: Barry vd. Heuvel <[email protected]>
1 parent fd43dfb commit 1386fe5

File tree

8 files changed

+85
-174
lines changed

8 files changed

+85
-174
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
"require": {
2020
"php": "^7.1|^8",
2121
"psr/log": "^1|^2|^3",
22-
"symfony/var-dumper": "^2.6|^3|^4|^5|^6"
22+
"symfony/var-dumper": "^4|^5|^6"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^7.5.20 || ^9.4.2",
25+
"phpunit/phpunit": ">=7.5.20 <10.0",
2626
"twig/twig": "^1.38|^2.7|^3.0"
2727
},
2828
"autoload": {

src/DebugBar/DataCollector/AggregatedCollector.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ public function __construct($name, $mergeProperty = null, $sort = false)
4848
/**
4949
* @param DataCollectorInterface $collector
5050
*/
51-
public function addCollector(DataCollectorInterface $collector)
51+
public function addCollector(DataCollectorInterface $collector) : void
5252
{
5353
$this->collectors[$collector->getName()] = $collector;
5454
}
5555

5656
/**
5757
* @return array
5858
*/
59-
public function getCollectors()
59+
public function getCollectors() : array
6060
{
6161
return $this->collectors;
6262
}
@@ -66,15 +66,15 @@ public function getCollectors()
6666
*
6767
* @param string $property
6868
*/
69-
public function setMergeProperty($property)
69+
public function setMergeProperty($property) : void
7070
{
7171
$this->mergeProperty = $property;
7272
}
7373

7474
/**
7575
* @return string
7676
*/
77-
public function getMergeProperty()
77+
public function getMergeProperty() : string
7878
{
7979
return $this->mergeProperty;
8080
}
@@ -87,7 +87,7 @@ public function getMergeProperty()
8787
*
8888
* @param bool|string $sort
8989
*/
90-
public function setSort($sort)
90+
public function setSort($sort) : void
9191
{
9292
$this->sort = $sort;
9393
}
@@ -103,7 +103,7 @@ public function getSort()
103103
/**
104104
* @return array
105105
*/
106-
public function collect()
106+
public function collect() : array
107107
{
108108
$aggregate = array();
109109
foreach ($this->collectors as $collector) {
@@ -123,7 +123,7 @@ public function collect()
123123
* @param array $data
124124
* @return array
125125
*/
126-
protected function sort($data)
126+
protected function sort($data) : array
127127
{
128128
if (is_string($this->sort)) {
129129
$p = $this->sort;
@@ -142,7 +142,7 @@ protected function sort($data)
142142
/**
143143
* @return string
144144
*/
145-
public function getName()
145+
public function getName() : string
146146
{
147147
return $this->name;
148148
}
@@ -164,7 +164,6 @@ public function offsetSet($key, $value): void
164164
* @param mixed $key
165165
* @return mixed
166166
*/
167-
168167
#[\ReturnTypeWillChange]
169168
public function offsetGet($key)
170169
{

src/DebugBar/DataCollector/PDO/TraceablePDO.php

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ public function __construct(PDO $pdo)
2323
$this->pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, [TraceablePDOStatement::class, [$this]]);
2424
}
2525

26-
/**
27-
* Initiates a transaction
28-
*
29-
* @link http://php.net/manual/en/pdo.begintransaction.php
30-
* @return bool TRUE on success or FALSE on failure.
31-
*/
32-
#[\ReturnTypeWillChange]
33-
public function beginTransaction()
26+
/**
27+
* Initiates a transaction
28+
*
29+
* @link http://php.net/manual/en/pdo.begintransaction.php
30+
* @return bool TRUE on success or FALSE on failure.
31+
*/
32+
public function beginTransaction() : bool
3433
{
3534
return $this->pdo->beginTransaction();
3635
}
@@ -41,8 +40,7 @@ public function beginTransaction()
4140
* @link http://php.net/manual/en/pdo.commit.php
4241
* @return bool TRUE on success or FALSE on failure.
4342
*/
44-
#[\ReturnTypeWillChange]
45-
public function commit()
43+
public function commit() : bool
4644
{
4745
return $this->pdo->commit();
4846
}
@@ -65,8 +63,7 @@ public function errorCode()
6563
* @link http://php.net/manual/en/pdo.errorinfo.php
6664
* @return array PDO::errorInfo returns an array of error information
6765
*/
68-
#[\ReturnTypeWillChange]
69-
public function errorInfo()
66+
public function errorInfo() : array
7067
{
7168
return $this->pdo->errorInfo();
7269
}
@@ -107,8 +104,7 @@ public function getAttribute($attribute)
107104
* @link http://php.net/manual/en/pdo.intransaction.php
108105
* @return bool TRUE if a transaction is currently active, and FALSE if not.
109106
*/
110-
#[\ReturnTypeWillChange]
111-
public function inTransaction()
107+
public function inTransaction() : bool
112108
{
113109
return $this->pdo->inTransaction();
114110
}
@@ -182,8 +178,7 @@ public function quote($string, $parameter_type = PDO::PARAM_STR)
182178
* @link http://php.net/manual/en/pdo.rollback.php
183179
* @return bool TRUE on success or FALSE on failure.
184180
*/
185-
#[\ReturnTypeWillChange]
186-
public function rollBack()
181+
public function rollBack() : bool
187182
{
188183
return $this->pdo->rollBack();
189184
}
@@ -196,8 +191,7 @@ public function rollBack()
196191
* @param mixed $value
197192
* @return bool TRUE on success or FALSE on failure.
198193
*/
199-
#[\ReturnTypeWillChange]
200-
public function setAttribute($attribute, $value)
194+
public function setAttribute($attribute, $value) : bool
201195
{
202196
return $this->pdo->setAttribute($attribute, $value);
203197
}
@@ -210,6 +204,7 @@ public function setAttribute($attribute, $value)
210204
* @param array $args
211205
* @return mixed The result of the call
212206
*/
207+
#[\ReturnTypeWillChange]
213208
protected function profileCall($method, $sql, array $args)
214209
{
215210
$trace = new TracedStatement($sql);
@@ -241,17 +236,17 @@ protected function profileCall($method, $sql, array $args)
241236
*
242237
* @param TracedStatement $stmt
243238
*/
244-
public function addExecutedStatement(TracedStatement $stmt)
239+
public function addExecutedStatement(TracedStatement $stmt) : void
245240
{
246241
$this->executedStatements[] = $stmt;
247242
}
248243

249244
/**
250245
* Returns the accumulated execution time of statements
251246
*
252-
* @return int
247+
* @return float
253248
*/
254-
public function getAccumulatedStatementsDuration()
249+
public function getAccumulatedStatementsDuration() : float
255250
{
256251
return array_reduce($this->executedStatements, function ($v, $s) { return $v + $s->getDuration(); });
257252
}
@@ -261,7 +256,7 @@ public function getAccumulatedStatementsDuration()
261256
*
262257
* @return int
263258
*/
264-
public function getMemoryUsage()
259+
public function getMemoryUsage() : int
265260
{
266261
return array_reduce($this->executedStatements, function ($v, $s) { return $v + $s->getMemoryUsage(); });
267262
}
@@ -271,7 +266,7 @@ public function getMemoryUsage()
271266
*
272267
* @return int
273268
*/
274-
public function getPeakMemoryUsage()
269+
public function getPeakMemoryUsage() : int
275270
{
276271
return array_reduce($this->executedStatements, function ($v, $s) { $m = $s->getEndMemory(); return $m > $v ? $m : $v; });
277272
}
@@ -281,7 +276,7 @@ public function getPeakMemoryUsage()
281276
*
282277
* @return TracedStatement[]
283278
*/
284-
public function getExecutedStatements()
279+
public function getExecutedStatements() : array
285280
{
286281
return $this->executedStatements;
287282
}
@@ -291,7 +286,7 @@ public function getExecutedStatements()
291286
*
292287
* @return TracedStatement[]
293288
*/
294-
public function getFailedExecutedStatements()
289+
public function getFailedExecutedStatements() : array
295290
{
296291
return array_filter($this->executedStatements, function ($s) { return !$s->isSuccess(); });
297292
}

src/DebugBar/DataCollector/PDO/TraceablePDOStatement.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public function bindColumn($column, &$param, $type = null, $maxlen = null, $driv
6262
* @param mixed $driver_options [optional]
6363
* @return bool TRUE on success or FALSE on failure.
6464
*/
65-
#[\ReturnTypeWillChange]
66-
public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null)
65+
public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null) : bool
6766
{
6867
$this->boundParameters[$parameter] = $variable;
6968
$args = array_merge([$parameter, &$variable], array_slice(func_get_args(), 2));
@@ -82,8 +81,7 @@ public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $
8281
* constants.
8382
* @return bool TRUE on success or FALSE on failure.
8483
*/
85-
#[\ReturnTypeWillChange]
86-
public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
84+
public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR) : bool
8785
{
8886
$this->boundParameters[$parameter] = $value;
8987
return call_user_func_array(['parent', 'bindValue'], func_get_args());
@@ -99,8 +97,7 @@ public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
9997
* @throws PDOException
10098
* @return bool TRUE on success or FALSE on failure.
10199
*/
102-
#[\ReturnTypeWillChange]
103-
public function execute($input_parameters = null)
100+
public function execute($input_parameters = null) : bool
104101
{
105102
$preparedId = spl_object_hash($this);
106103
$boundParameters = $this->boundParameters;

0 commit comments

Comments
 (0)