Skip to content

Join::join() raises TypeError instead of InvalidArgumentException for an invalid name without a leading string #206

Closed

Description

@simon-mundy

Package Version

0.6.x-dev @ e022af5c

Php Version

8.3, 8.4, 8.5

Database Engine

Any

Basic Information

Join::join() rejects a name array that is not a single-element associative array, and passes the array's first element into the message (Join.php#L97):

throw Exception\InvalidArgumentException::forInvalidJoinName(array_shift($name));

forInvalidJoinName() takes a string (InvalidArgumentException.php#L134). When the first element is not a string (an empty array, an unaliased Select, an integer), building the exception raises a TypeError first.

This came in with #192, which replaced sprintf(...) (which accepted any type) with the typed named constructor. #192 notes that the same unsoundness was re-attributed to forInvalidJoinName in the analyzer baseline.

Steps to Reproduce

  1. (new Join())->join([], 'a = b')
  2. (new Join())->join([new Select('foo')], 'a = b')
  3. (new Join())->join([5], 'a = b')

Expected Behavior

PhpDb\Sql\Exception\InvalidArgumentException. Where the element is not a string, the message names its type, e.g. join() expects 'int' as a single element associative array.

Actual behavior?

TypeError: PhpDb\Sql\Exception\InvalidArgumentException::forInvalidJoinName(): Argument #1 ($name) must be of type string, null given, called in src/Sql/Join.php on line 115
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions