Skip to content

Commit 435933b

Browse files
committed
#hakre memo: fixup! Update PrintfHelper.php
@phpstan-bot: perhaps you can spend some LLM-inference on the two comments, the earlier for feasibility, the later with your bets when this could happen.
1 parent 5742f2b commit 435933b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/Rules/Functions/PrintfHelper.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,29 @@ public function getPrintfPlaceholders(string $format): ?array
4444
public function getScanfPlaceholdersCount(string $format): ?int
4545
{
4646
try {
47+
// if we would *know* that simple downgrader can handle
48+
// Throwable -> ErrorException then 7.4 required error
49+
// handler could be injected this way into the try/catch
50+
// & appending finally as an extension. *dreaming*
4751
set_error_handler(
4852
static function ($s, $m, ...$vv) {
4953
$vv = array_slice($vv, 0, 2);
5054
throw new ErrorException($m, 0, $s, ...$vv);
5155
},
5256
);
53-
$nFormat = '%n' . $format;
57+
$nFormat = '%*n' . $format;
5458
$result = sscanf('', $nFormat);
5559
} catch (Throwable) {
5660
return null;
5761
} finally {
5862
restore_error_handler();
5963
}
64+
// one day phpstan may report here that $result can never be null for sscanf('', $nFormat),
65+
// which is actually correct: https://3v4l.org/rO7Ni
6066
if ($result === null) {
6167
return null;
6268
}
63-
return count($result) + -1;
69+
return count($result);
6470
}
6571

6672
/**

0 commit comments

Comments
 (0)