GeneratorManager: fixed addGenerator() being case-sensitive when overwrite=true

this was caused by 083a1e1ff6b6ff5c0c1ba14250d2b026af103b90.

This was discovered by a new PHPStan rule I'm working on, which disallows overwriting the values of parameter variables. During the refactor of this function to correct the error, another error appeared: Variable might not be defined.

This is yet another excellent example of why mutability is bad.
This commit is contained in:
Dylan K. Taylor 2021-12-12 21:58:07 +00:00
parent e06eefeab0
commit 0a58fd5472
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -72,7 +72,8 @@ final class GeneratorManager{
public function addGenerator(string $class, string $name, \Closure $presetValidator, bool $overwrite = false) : void{
Utils::testValidInstance($class, Generator::class);
if(!$overwrite and isset($this->list[$name = strtolower($name)])){
$name = strtolower($name);
if(!$overwrite and isset($this->list[$name])){
throw new \InvalidArgumentException("Alias \"$name\" is already assigned");
}