Skip to content

AST: generic operator support #589

@hemberger

Description

@hemberger

I've been looking into handling the case where QueryScope::getType receives an instance of SqlFtw\Sql\Expression\Operator as input. Currently, this falls back to simply returning MixedType, which renders the AST-derived types mostly useless. It would be much more powerful if we could get the true type by applying the operator.

Most of the operators will have a direct analog to PHP operators, and so the logic in PHPStan\Analyser\MutatingScope and PHPStan\Reflection\InitializerExprTypeResolver for handling operators has much of the logic we need already. However, this logic handles types that are irrelevant to SQL as well (such as arrays etc.), and it is buried so deep in the PHPStan architecture that it is likely unreasonable (or inappropriate) to use within QueryScope.

If we want to support SQL operators, would we need to duplicate all this logic from PHPStan? Even if we omit the parts that are irrelevant to SQL, this seems like it would be quite a lot of code duplication. Would it be reasonable to consider refactoring PHPStan to create a generic set of "type math" classes?

@staabm I'd be very grateful to hear your opinions about how to approach this, and whether or not it's something you'd like me to work on. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions