Fix #43: annotate batch() and getDefaultDriver() on the Quantum facade - #94
Merged
Conversation
Quantum::batch() worked at runtime through Facade::__callStatic() but was missing from the @method annotations, so IDEs and static analysis treated it as undefined. The docblock now lists every public method QuantumManager declares, and a test compares the annotations with the manager's public methods so the two cannot drift apart again. Closes #43
batch() accepts any array of circuits, since the manager reindexes it, and driver() accepts the enum cases Manager::driver() resolves through driverAlias(). The drift test now parses each annotation, checks the two lists in both directions and compares the annotated return types with the declared ones, instead of only looking for method names.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
QuantumManager::batch()is public, documented in the README and reachable through the facade at runtime, butQuantum's docblock did not list it as an@method staticannotation, so IDE completion and Larastan treatedQuantum::batch()as undefined.getDefaultDriver()was missing for the same reason, and two existing annotations advertised narrower parameter types than the manager accepts.Plan
Make the facade docblock faithful to the manager and add a test that keeps it that way: every public method the manager declares must be annotated, no annotation may name a method the manager no longer has, and each annotated return type must match the declared one.
Changes
src/Facades/Quantum.php:@method static BatchBuilder batch(array<array-key, CircuitBuilder> $circuits, ?string $driver = null)(the manager runsarray_values()on the input, so keyed arrays are valid),@method static string getDefaultDriver(), anddriver(string|\UnitEnum|null $driver = null)to matchManager::driver(), which resolves enum cases throughdriverAlias().tests/Unit/Facades/QuantumFacadeTest.php(new): parses the@methodlines (tolerating an omitted return type and generics with spaces) and checks three things by reflection: every methodQuantumManagerdeclares is annotated; no annotation is stale; annotated return types match declared ones.No runtime change, no config change, no new dependencies.
Tests
The first test fails on
main(batchandgetDefaultDrivermissing); the return-type test would catch a wrong annotation such asbatch()returningCircuitBuilder.Local: pint passed, pest 793 tests passed.
Closes #43