Skip to content

Commit 09e906f

Browse files
[PhpUnitBridge] Add some more native types
1 parent 16a0bca commit 09e906f

File tree

7 files changed

+47
-167
lines changed

7 files changed

+47
-167
lines changed

ClassExistsMock.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ class ClassExistsMock
2424
* Configures the classes to be checked upon existence.
2525
*
2626
* @param array $classes Mocked class names as keys (case-sensitive, without leading root namespace slash) and booleans as values
27-
*
28-
* @return void
2927
*/
30-
public static function withMockedClasses(array $classes)
28+
public static function withMockedClasses(array $classes): void
3129
{
3230
self::$classes = $classes;
3331
}
@@ -36,59 +34,42 @@ public static function withMockedClasses(array $classes)
3634
* Configures the enums to be checked upon existence.
3735
*
3836
* @param array $enums Mocked enums names as keys (case-sensitive, without leading root namespace slash) and booleans as values
39-
*
40-
* @return void
4137
*/
42-
public static function withMockedEnums(array $enums)
38+
public static function withMockedEnums(array $enums): void
4339
{
4440
self::$enums = $enums;
4541
self::$classes += $enums;
4642
}
4743

48-
/**
49-
* @return bool
50-
*/
51-
public static function class_exists($name, $autoload = true)
44+
public static function class_exists($name, $autoload = true): bool
5245
{
5346
$name = ltrim($name, '\\');
5447

5548
return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \class_exists($name, $autoload);
5649
}
5750

58-
/**
59-
* @return bool
60-
*/
61-
public static function interface_exists($name, $autoload = true)
51+
public static function interface_exists($name, $autoload = true): bool
6252
{
6353
$name = ltrim($name, '\\');
6454

6555
return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \interface_exists($name, $autoload);
6656
}
6757

68-
/**
69-
* @return bool
70-
*/
71-
public static function trait_exists($name, $autoload = true)
58+
public static function trait_exists($name, $autoload = true): bool
7259
{
7360
$name = ltrim($name, '\\');
7461

7562
return isset(self::$classes[$name]) ? (bool) self::$classes[$name] : \trait_exists($name, $autoload);
7663
}
7764

78-
/**
79-
* @return bool
80-
*/
81-
public static function enum_exists($name, $autoload = true)
65+
public static function enum_exists($name, $autoload = true):bool
8266
{
8367
$name = ltrim($name, '\\');
8468

8569
return isset(self::$enums[$name]) ? (bool) self::$enums[$name] : \enum_exists($name, $autoload);
8670
}
8771

88-
/**
89-
* @return void
90-
*/
91-
public static function register($class)
72+
public static function register($class): void
9273
{
9374
$self = static::class;
9475

ClockMock.php

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ class ClockMock
1919
{
2020
private static $now;
2121

22-
/**
23-
* @return bool|null
24-
*/
25-
public static function withClockMock($enable = null)
22+
public static function withClockMock($enable = null): ?bool
2623
{
2724
if (null === $enable) {
2825
return null !== self::$now;
@@ -33,10 +30,7 @@ public static function withClockMock($enable = null)
3330
return null;
3431
}
3532

36-
/**
37-
* @return int
38-
*/
39-
public static function time()
33+
public static function time(): int
4034
{
4135
if (null === self::$now) {
4236
return \time();
@@ -45,10 +39,7 @@ public static function time()
4539
return (int) self::$now;
4640
}
4741

48-
/**
49-
* @return int
50-
*/
51-
public static function sleep($s)
42+
public static function sleep($s): int
5243
{
5344
if (null === self::$now) {
5445
return \sleep($s);
@@ -59,10 +50,7 @@ public static function sleep($s)
5950
return 0;
6051
}
6152

62-
/**
63-
* @return void
64-
*/
65-
public static function usleep($us)
53+
public static function usleep($us): void
6654
{
6755
if (null === self::$now) {
6856
\usleep($us);
@@ -71,6 +59,9 @@ public static function usleep($us)
7159
}
7260
}
7361

62+
/**
63+
* @return string|float
64+
*/
7465
public static function microtime($asFloat = false)
7566
{
7667
if (null === self::$now) {
@@ -84,10 +75,7 @@ public static function microtime($asFloat = false)
8475
return sprintf('%0.6f00 %d', self::$now - (int) self::$now, (int) self::$now);
8576
}
8677

87-
/**
88-
* @return string
89-
*/
90-
public static function date($format, $timestamp = null)
78+
public static function date($format, $timestamp = null): string
9179
{
9280
if (null === $timestamp) {
9381
$timestamp = self::time();
@@ -96,10 +84,7 @@ public static function date($format, $timestamp = null)
9684
return \date($format, $timestamp);
9785
}
9886

99-
/**
100-
* @return string
101-
*/
102-
public static function gmdate($format, $timestamp = null)
87+
public static function gmdate($format, $timestamp = null): string
10388
{
10489
if (null === $timestamp) {
10590
$timestamp = self::time();
@@ -124,10 +109,7 @@ public static function hrtime($asNumber = false)
124109
return [(int) self::$now, (int) $ns];
125110
}
126111

127-
/**
128-
* @return void
129-
*/
130-
public static function register($class)
112+
public static function register($class): void
131113
{
132114
$self = static::class;
133115

DeprecationErrorHandler.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,7 @@ private function getConfiguration()
278278
return $this->configuration = Configuration::fromUrlEncodedString((string) $mode);
279279
}
280280

281-
/**
282-
* @param string $str
283-
* @param bool $red
284-
*
285-
* @return string
286-
*/
287-
private static function colorize($str, $red)
281+
private static function colorize(string $str, bool $red): string
288282
{
289283
if (!self::hasColorSupport()) {
290284
return $str;
@@ -296,12 +290,9 @@ private static function colorize($str, $red)
296290
}
297291

298292
/**
299-
* @param string[] $groups
300-
* @param Configuration $configuration
301-
*
302-
* @throws \InvalidArgumentException
293+
* @param string[] $groups
303294
*/
304-
private function displayDeprecations($groups, $configuration)
295+
private function displayDeprecations(array $groups, Configuration $configuration): void
305296
{
306297
$cmp = function ($a, $b) {
307298
return $b->count() - $a->count();
@@ -397,10 +388,8 @@ private static function getPhpUnitErrorHandler(): callable
397388
*
398389
* Reference: Composer\XdebugHandler\Process::supportsColor
399390
* https://github.com/composer/xdebug-handler
400-
*
401-
* @return bool
402391
*/
403-
private static function hasColorSupport()
392+
private static function hasColorSupport(): bool
404393
{
405394
if (!\defined('STDOUT')) {
406395
return false;

DeprecationErrorHandler/Configuration.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Configuration
7070
* @param string $baselineFile The path to the baseline file
7171
* @param string|null $logFile The path to the log file
7272
*/
73-
private function __construct(array $thresholds = [], $regex = '', $verboseOutput = [], $ignoreFile = '', $generateBaseline = false, $baselineFile = '', $logFile = null)
73+
private function __construct(array $thresholds = [], string $regex = '', array $verboseOutput = [], string $ignoreFile = '', bool $generateBaseline = false, string $baselineFile = '', string $logFile = null)
7474
{
7575
$groups = ['total', 'indirect', 'direct', 'self'];
7676

@@ -279,10 +279,7 @@ public function writeBaseline(): void
279279
file_put_contents($this->baselineFile, json_encode($map, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES));
280280
}
281281

282-
/**
283-
* @param string $message
284-
*/
285-
public function shouldDisplayStackTrace($message): bool
282+
public function shouldDisplayStackTrace(string $message): bool
286283
{
287284
return '' !== $this->regex && preg_match($this->regex, $message);
288285
}
@@ -308,10 +305,9 @@ public function getLogFile(): ?string
308305
}
309306

310307
/**
311-
* @param string $serializedConfiguration an encoded string, for instance
312-
* max[total]=1234&max[indirect]=42
308+
* @param string $serializedConfiguration An encoded string, for instance max[total]=1234&max[indirect]=42
313309
*/
314-
public static function fromUrlEncodedString($serializedConfiguration): self
310+
public static function fromUrlEncodedString(string $serializedConfiguration): self
315311
{
316312
parse_str($serializedConfiguration, $normalizedConfiguration);
317313
foreach (array_keys($normalizedConfiguration) as $key) {

0 commit comments

Comments
 (0)