Handle config defaults better - #1619
Conversation
| if (! is_file($filename)) { | ||
| throw new RuntimeException("Configuration file $filename not found."); | ||
| } | ||
|
|
There was a problem hiding this comment.
A question, about this... not strictly relevant to the patch, but still... why do we make $filename an argument? We only ever use pinc/site_vars.php and that's from the one callsite at the end of this file, right? Having require $filename; like this makes life more difficult on static analysers like PHPStan: they choke on the non-literal argument, and can't see the dependency.
There was a problem hiding this comment.
The thought was that for handling some of our upgrade checks it will make it easier to point to another config file to load the values within the script, effectively:
require_once(__DIR__ . "/../pinc/SiteConfig.inc");
SiteConfig::load($some_config_file); // <-- overwrite the values from the new config fileI'm still finalizing that code now and if we don't actually need it I can rip the configurable-ness out.
| // if there is no forum defined, we can't do anything | ||
| if ($forum_id == null) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
A minor stylistic thing, but if you wanted to, you could fuse this with the assignment above: PHP scopes assignments within if conditions to the block containing the if.
if (($forum_id = ProjectStates::get_forum($this->state)) == null) {
return null;
}
There was a problem hiding this comment.
If PHP is scoping the assignment to within the if() block then I don't want it here because it's used outside the if() scope, right? The other case in ProjcatTransition.inc I do.
There was a problem hiding this comment.
Perhaps surprisingly, the scoping is the block that contains the if, not the the block with the 'then' body.
function foo() {
if (($r = rand(0, 100)) > 50) {
echo "$r is luckier than average!\n"; // <-- in scope here
}
echo "You rolled $r\n"; // <-- but also in scope here
}
foo();
5d80301 to
f738725
Compare
f738725 to
8737ad9
Compare
This is a set of small commits that better support the default (often
null) configuration values set inSiteConfig. These are always set on TEST and PROD but new sites and test configurations don't necessarily need to set them and the default ofnullshould work.This is prep work to remove the bash-based configuration mechanism.