in src/markdown-extensions/extracted-code-blocks/FilterBase.php [405:457]
private static function hasValidOutputFileSet(
string $hack_file_path,
Files $expect,
Files $example,
Files $expectf,
Files $expectregex,
bool $needs_example,
): bool {
// Not all of these are allowed to exist at the same time, but at this point
// we may not know which exact combination will be generated, so for the
// purposes of self::$validFiles we have to consider them all valid. There
// are additional checks below for any invalid combinations.
self::$validFiles[] = $hack_file_path.'.'.$expect;
self::$validFiles[] = $hack_file_path.'.'.$expectf;
self::$validFiles[] = $hack_file_path.'.'.$expectregex;
self::$validFiles[] = $hack_file_path.'.'.$example;
$has_expect = \file_exists($hack_file_path.'.'.$expect);
$has_expectf = \file_exists($hack_file_path.'.'.$expectf);
$has_expectregex = \file_exists($hack_file_path.'.'.$expectregex);
$has_example = \file_exists($hack_file_path.'.'.$example);
if ($has_expect) {
// Simple case, .expect must be the only file.
invariant(
!$has_expectf && !$has_expectregex && !$has_example,
'%s has a .%s file, but also other conflicting expect/output files!',
$hack_file_path,
$expect,
);
return true;
}
// Exactly one of these must be present, but never both.
invariant(
!$has_expectf || !$has_expectregex,
'%s has both a .%s and a conflicting .%s file!',
$hack_file_path,
$expectf,
$expectregex,
);
// Example file should exist if and only if $needs_example is set.
invariant(
$needs_example || !$has_example,
'%s has a redundant .%s file!',
$hack_file_path,
$example,
);
return (!$needs_example || $has_example) &&
($has_expectf || $has_expectregex);
}