Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved type information with psalm annotations on query and command buses #15

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

butschster
Copy link
Member

@butschster butschster commented Sep 30, 2023

In this Pull Request, we have enriched the type information of query and command buses by integrating Psalm annotations. This enhancement facilitates developers by offering precise return type definitions for commands and queries.

Here's a snapshot of what has been done:

  1. For commands, you can now clearly define the return type. Here is an example utilizing @implements CommandInterface<...> annotation:
use Spiral\Cqrs\CommandInterface;

/**
 * @implements CommandInterface<StoreUserResult>
 */
final readonly class StoreUserCommand implements CommandInterface
{
    public function __construct(
        public string $username,
        public string $email,
    ) {
    }
}
  1. Similarly, for queries, the return type can be defined as shown in the UserListQuery class example below:
use Spiral\Cqrs\QueryInterface;

/**
 * @implements QueryInterface<UserListResult>
 */
final readonly class UserListQuery implements QueryInterface
{

}

With these annotations in place, your IDE will now provide suggestive autocomplete options, making the code interaction more intuitive and error-prone.

Here are examples showing how IDE suggestions would appear post this update:

$bus->ask(new UserListQuery())->...;
$bus->dispatch(new StoreUserCommand(...))->...;

image

This update aims to streamline the development process by providing clearer, type-informed interactions within the codebase.

@butschster butschster added the enhancement New feature or request label Sep 30, 2023
@butschster butschster self-assigned this Sep 30, 2023
@iGrog
Copy link

iGrog commented Nov 29, 2023

When do you plan it to merge to the master branch?

@butschster butschster merged commit 8782a5b into master Nov 30, 2023
3 checks passed
@butschster butschster deleted the feature/coomand-query-suggestions branch November 30, 2023 08:34
@butschster
Copy link
Member Author

When do you plan it to merge to the master branch?

Done! Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants