Skip to content

Commit 27d957a

Browse files
committed
Refactor tri-state Context::forceRegeneration to two booleans
1 parent ec7a0ad commit 27d957a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

build/gen_stub.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ function processStubFile(string $stubFile, Context $context): ?FileInfo {
4747
$stubCode = file_get_contents($stubFile);
4848
$stubHash = computeStubHash($stubCode);
4949
$oldStubHash = extractStubHash($arginfoFile);
50-
if ($stubHash === $oldStubHash && $context->forceRegeneration === false) {
50+
if ($stubHash === $oldStubHash && !$context->forceParse) {
5151
/* Stub file did not change, do not regenerate. */
5252
return null;
5353
}
5454

5555
initPhpParser();
5656
$fileInfo = parseStubFile($stubCode);
5757
$arginfoCode = generateArgInfoCode($fileInfo, $stubHash);
58-
if ($context->forceRegeneration === true && file_put_contents($arginfoFile, $arginfoCode)) {
58+
if ($context->forceRegeneration && file_put_contents($arginfoFile, $arginfoCode)) {
5959
echo "Saved $arginfoFile\n";
6060
}
6161

@@ -94,7 +94,9 @@ function extractStubHash(string $arginfoFile): ?string {
9494
}
9595

9696
class Context {
97-
/** @var bool|null */
97+
/** @var bool */
98+
public $forceParse = false;
99+
/** @var bool */
98100
public $forceRegeneration = false;
99101
}
100102

@@ -1267,8 +1269,8 @@ function initPhpParser() {
12671269
$context = new Context;
12681270
$printParameterStats = isset($options["parameter-stats"]);
12691271
$verify = isset($options["verify"]);
1270-
$context->forceRegeneration =
1271-
isset($options["f"]) || isset($options["force-regeneration"]) ? true : ($printParameterStats || $verify ? null : false);
1272+
$context->forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]);
1273+
$context->forceParse = $context->forceRegeneration || $printParameterStats || $verify;
12721274

12731275
if (isset($options["h"]) || isset($options["help"])) {
12741276
die("\nusage: gen-stub.php [ -f | --force-regeneration ] [ --parameter-stats ] [ --verify ] [ -h | --help ] [ name.stub.php | directory ]\n\n");

0 commit comments

Comments
 (0)