Skip to content

Commit

Permalink
Added support for self & static keywords in array_reduce callables
Browse files Browse the repository at this point in the history
  • Loading branch information
elnoro committed Jun 29, 2021
1 parent 0196afc commit 770075b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<extensions>
<extension class="Weirdan\PhpUnitAppVeyorReporter\Listener"></extension>
</extensions>
<!-- <extensions>-->
<!-- <extension class="Weirdan\PhpUnitAppVeyorReporter\Listener"></extension>-->
<!-- </extensions>-->
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,14 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev

[$callable_fq_class_name, $method_name] = explode('::', $mapping_function_id_part);

if (in_array($callable_fq_class_name, ['self', 'static', 'parent'], true)) {
if (in_array($callable_fq_class_name, ['self', 'static'], true)) {
$callable_fq_class_name = $statements_source->getFQCLN();
if ($callable_fq_class_name === null) {
continue;
}
}

if ($callable_fq_class_name === 'parent') {
continue;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/ArrayFunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,28 @@ function (int $carry, int $item) : int {
'$function_call_result' => 'int',
],
],
'arrayReduceStaticMethods' => [
'<?php
$arr = [2, 3, 4, 5];
class C {
public static function multiply (int $carry, int $item) : int {
return $carry * $item;
}
public static function multiplySelf(array $arr): int {
return array_reduce($arr, [self::class, "multiply"], 1);
}
public static function multiplyStatic(array $arr): int {
return array_reduce($arr, [static::class, "multiply"], 1);
}
}
$self_call_result = C::multiplySelf($arr);
$static_call_result = C::multiplyStatic($arr);',
'assertions' => [],
],
'arrayReduceMixedReturn' => [
'<?php
$arr = [2, 3, 4, 5];
Expand Down

0 comments on commit 770075b

Please sign in to comment.