Skip to content

Fix Client::setProtocol() always throwing - #7

Open
tomsommer wants to merge 1 commit into
ArrayAccess:mainfrom
tomsommer:fix-set-protocol
Open

tomsommer wants to merge 1 commit into
ArrayAccess:mainfrom
tomsommer:fix-set-protocol

Conversation

@tomsommer

Copy link
Copy Markdown

Client::setProtocol() could never succeed:

  • it stored the protocol class name ($obj) instead of the given instance, and
  • after the matching type was found, break fell through to the throw, so every call threw InvalidServiceDefinitionException: Service protocol "..." is not supported.

Now the instance is stored and the method returns once a matching protocol type is found. An unsupported protocol still throws.

$client = new Client();
$protocol = new DomainProtocol($client, $myDomainService);
$client->setProtocol($protocol);
$client->getProtocol(Client::DOMAIN) === $protocol; // true, previously threw

phpcs and phpstan pass.

The loop stored the protocol class name instead of the given instance
and then fell through to the exception after break. Store the instance
and return once a matching protocol type is found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant