Skip to content

Commit

Permalink
added missing typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 17, 2018
1 parent 0ef12af commit a3e31de
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Utils/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public static function flatten(array $arr, bool $preserveKeys = false): array
{
$res = [];
$cb = $preserveKeys
? function ($v, $k) use (&$res) { $res[$k] = $v; }
: function ($v) use (&$res) { $res[] = $v; };
? function ($v, $k) use (&$res): void { $res[$k] = $v; }
: function ($v) use (&$res): void { $res[] = $v; };
array_walk_recursive($arr, $cb);
return $res;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public static function invokeArgs($callable, array $args = [])
*/
public static function invokeSafe(string $function, array $args, callable $onError)
{
$prev = set_error_handler(function ($severity, $message, $file) use ($onError, &$prev, $function) {
$prev = set_error_handler(function ($severity, $message, $file) use ($onError, &$prev, $function): ?bool {
if ($file === __FILE__) {
$msg = $message;
if (ini_get('html_errors')) {
$msg = html_entity_decode(strip_tags($msg));
}
$msg = preg_replace("#^$function\(.*?\): #", '', $msg);
if ($onError($msg, $severity) !== false) {
return;
return null;
}
}
return $prev ? $prev(...func_get_args()) : false;
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static function fromFile(string $file, int &$detectedFormat = null)
$detectedFormat = null;
throw new UnknownImageFileException(is_file($file) ? "Unknown type of file '$file'." : "File '$file' not found.");
}
return new static(Callback::invokeSafe('imagecreatefrom' . image_type_to_extension($detectedFormat, false), [$file], function (string $message) {
return new static(Callback::invokeSafe('imagecreatefrom' . image_type_to_extension($detectedFormat, false), [$file], function (string $message): void {
throw new ImageException($message);
}));
}
Expand All @@ -174,7 +174,7 @@ public static function fromString(string $s, int &$detectedFormat = null)
$detectedFormat = isset(self::$formats[$tmp]) ? $tmp : null;
}

return new static(Callback::invokeSafe('imagecreatefromstring', [$s], function (string $message) {
return new static(Callback::invokeSafe('imagecreatefromstring', [$s], function (string $message): void {
throw new ImageException($message);
}));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Random
*/
public static function generate(int $length = 10, string $charlist = '0-9a-z'): string
{
$charlist = count_chars(preg_replace_callback('#.-.#', function (array $m) {
$charlist = count_chars(preg_replace_callback('#.-.#', function (array $m): string {
return implode('', range($m[0][0], $m[0][2]));
}, $charlist), 3);
$chLen = strlen($charlist);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public static function replace(string $subject, $pattern, $replacement = null, i
/** @internal */
public static function pcre(string $func, array $args)
{
$res = Callback::invokeSafe($func, $args, function (string $message) use ($args) {
$res = Callback::invokeSafe($func, $args, function (string $message) use ($args): void {
// compile-time error, not detectable by preg_last_error
throw new RegexpException($message . ' in pattern: ' . implode(' or ', (array) $args[0]));
});
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@mkdir(TEMP_DIR);


function test(\Closure $function)
function test(\Closure $function): void
{
$function();
}

0 comments on commit a3e31de

Please sign in to comment.