Skip to content

Commit 768b99d

Browse files
minor #33770 Add types to constructors and private/final/internal methods (Batch III) (derrabus)
This PR was squashed before being merged into the 4.4 branch (closes #33770). Discussion ---------- Add types to constructors and private/final/internal methods (Batch III) | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #32179, #33228 | License | MIT | Doc PR | N/A Followup to #33709, this time with: * Validator * VarDumper * Workflow * Yaml * all bridges * all bundles That should be the final batch. 😃 Commits ------- 6493902287 Add types to constructors and private/final/internal methods (Batch III)
2 parents a37b6b9 + 5a4d5a8 commit 768b99d

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

Caster/Caster.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ class Caster
4141
* Casts objects to arrays and adds the dynamic property prefix.
4242
*
4343
* @param object $obj The object to cast
44-
* @param string $class The class of the object
4544
* @param bool $hasDebugInfo Whether the __debugInfo method exists on $obj or not
4645
*
4746
* @return array The array-cast of the object, with prefixed dynamic properties
4847
*/
49-
public static function castObject($obj, $class, $hasDebugInfo = false): array
48+
public static function castObject($obj, string $class, bool $hasDebugInfo = false): array
5049
{
5150
$a = $obj instanceof \Closure ? [] : (array) $obj;
5251

@@ -110,7 +109,7 @@ public static function castObject($obj, $class, $hasDebugInfo = false): array
110109
*
111110
* @return array The filtered array
112111
*/
113-
public static function filter(array $a, $filter, array $listedProperties = [], &$count = 0): array
112+
public static function filter(array $a, int $filter, array $listedProperties = [], ?int &$count = 0): array
114113
{
115114
$count = 0;
116115

@@ -151,7 +150,7 @@ public static function filter(array $a, $filter, array $listedProperties = [], &
151150
return $a;
152151
}
153152

154-
public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, $isNested)
153+
public static function castPhpIncompleteClass(\__PHP_Incomplete_Class $c, array $a, Stub $stub, bool $isNested): array
155154
{
156155
if (isset($a['__PHP_Incomplete_Class_Name'])) {
157156
$stub->class .= '('.$a['__PHP_Incomplete_Class_Name'].')';

Caster/DateCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function castInterval(\DateInterval $interval, array $a, Stub $stu
5454
return $filter & Caster::EXCLUDE_VERBOSE ? $i : $i + $a;
5555
}
5656

57-
private static function formatInterval(\DateInterval $i)
57+
private static function formatInterval(\DateInterval $i): string
5858
{
5959
$format = '%R ';
6060

Caster/MemcachedCaster.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function castMemcached(\Memcached $c, array $a, Stub $stub, $isNes
3535
return $a;
3636
}
3737

38-
private static function getNonDefaultOptions(\Memcached $c)
38+
private static function getNonDefaultOptions(\Memcached $c): array
3939
{
4040
self::$defaultOptions = self::$defaultOptions ?? self::discoverDefaultOptions();
4141
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
@@ -50,7 +50,7 @@ private static function getNonDefaultOptions(\Memcached $c)
5050
return $nonDefaultOptions;
5151
}
5252

53-
private static function discoverDefaultOptions()
53+
private static function discoverDefaultOptions(): array
5454
{
5555
$defaultMemcached = new \Memcached();
5656
$defaultMemcached->addServer('127.0.0.1', 11211);
@@ -65,7 +65,7 @@ private static function discoverDefaultOptions()
6565
return $defaultOptions;
6666
}
6767

68-
private static function getOptionConstants()
68+
private static function getOptionConstants(): array
6969
{
7070
$reflectedMemcached = new \ReflectionClass(\Memcached::class);
7171

Caster/ReflectionCaster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public static function getSignature(array $a)
363363
return $signature;
364364
}
365365

366-
private static function addExtra(&$a, \Reflector $c)
366+
private static function addExtra(array &$a, \Reflector $c)
367367
{
368368
$x = isset($a[Caster::PREFIX_VIRTUAL.'extra']) ? $a[Caster::PREFIX_VIRTUAL.'extra']->value : [];
369369

@@ -379,7 +379,7 @@ private static function addExtra(&$a, \Reflector $c)
379379
}
380380
}
381381

382-
private static function addMap(&$a, \Reflector $c, $map, $prefix = Caster::PREFIX_VIRTUAL)
382+
private static function addMap(array &$a, \Reflector $c, array $map, string $prefix = Caster::PREFIX_VIRTUAL)
383383
{
384384
foreach ($map as $k => $m) {
385385
if (method_exists($c, $m) && false !== ($m = $c->$m()) && null !== $m) {

Caster/SplCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static function castWeakReference(\WeakReference $c, array $a, Stub $stub
203203
return $a;
204204
}
205205

206-
private static function castSplArray($c, array $a, Stub $stub, $isNested)
206+
private static function castSplArray($c, array $a, Stub $stub, bool $isNested): array
207207
{
208208
$prefix = Caster::PREFIX_VIRTUAL;
209209
$class = $stub->class;

Test/VarDumperTestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function getDump($data, $key = null, $filter = 0)
7676
return rtrim($dumper->dump($data, true));
7777
}
7878

79-
private function prepareExpectation($expected, int $filter)
79+
private function prepareExpectation($expected, int $filter): string
8080
{
8181
if (!\is_string($expected)) {
8282
$expected = $this->getDump($expected, null, $filter);

0 commit comments

Comments
 (0)