Roave/BetterReflection

Enforce `StringSourceLocator` to be built with a `non-empty-string`

Ocramius opened this issue · 0 comments

Currently, a StringSourceLocator can be constructed with an empty string, but will crash at runtime when doing so:

/**
* @throws EmptyPhpSourceCode
*/
public function __construct(private string $source, Locator $astLocator)
{
parent::__construct($astLocator);
if (empty($source)) {
// Whilst an empty string is still "valid" PHP code, there is no
// point in us even trying to parse it because we won't find what
// we are looking for, therefore this throws an exception
throw new EmptyPhpSourceCode(
'Source code string was empty',
);
}
}

We should really get rid of the exception, and instead enforce non-empty-string as input.