Scramble v0.13.55 is a small, focused patch release: one change to the type inference engine, bundling three closely related fixes. It's a subtle one, but it touches a pattern that appears in almost every object-oriented PHP codebase — methods that declare self or parent as their return type. Those methods were silently losing the richer types Scramble inferred from their bodies, which meant vaguer schemas in the generated API documentation. This release teaches the analyzer to resolve self and parent to concrete classes, so the best available type wins.
The highlight: inferred return types survive
Scramble's static analyzer works out what a method body actually returns, then weighs that inferred type against the declared return type. When the inferred type is compatible with the declaration, Scramble keeps it — the inferred type is nearly always the more informative of the two, because it can carry concrete class names, template types captured from the constructor, and other detail a bare declaration can't express.
For methods declaring : self or : parent, that comparison was quietly broken. The declared side stayed an unresolved keyword — literally self or parent — while the inferred side came back as a concrete class. A keyword is never compatible with a class, so the check failed and Scramble fell back on the bare declaration, throwing away everything the body analysis had discovered.
class InvoiceRepository
{
public function forCustomer(Customer $customer): self
{
return new static($customer);
}
}
Here the body gives Scramble a concrete class, complete with any generics the constructor establishes. Before this release, that detail was discarded and the documentation degraded to a plain self; now the fuller inferred type survives and flows downstream into your API docs.
What changed under the hood
Three related fixes landed in the analyzer, and they work as a set:
selfresolves to the declaring class. Before deciding whether an inferred return type is compatible, a: selfdeclaration is rewritten to the fully-qualified name of the class that declares the method.parentresolves to the declaring class's parent. A: parentdeclaration is resolved to the parent class of the class that declares the method.parentresolves through the defining class. References toparentinside a method body are resolved through the method's defining class rather than the class in the current scope.
That last one fixes a genuinely tricky edge case:
class A {}
class B extends A
{
public function replicate(): parent
{
return new parent(); // in B, parent means A
}
}
class C extends B {}
When Scramble analyzed this through C — say, because an endpoint called (new C)->replicate() — parent was resolved against the caller's scope and pointed to B. But the method body lives in B, where parent means A. Resolution now goes through the defining class, so the type comes out as A — the class the code actually means — no matter which subclass triggers the call.
What this means for your documentation
If your code leans on inheritance — base repositories, fluent builders, framework-style base classes — you should see more precise response types in the generated OpenAPI document without adding a single annotation. Where a method used to document as a vague self or parent, the concrete inferred class now appears, including generic parameters captured from constructors. Endpoints that traverse fluent chains through self-returning methods benefit too, since each hop now preserves the type detail Scramble already knew.
Upgrading
Nothing to configure and nothing to learn: bump to v0.13.55, regenerate your documentation, and the sharper types appear. If you previously papered over vague self/parent output with extra docblock annotations, it may be worth revisiting them — though nothing breaks if you leave them in place.
Key takeaways
- Methods declaring
: selfor: parentkeep their inferred return types whenever those are compatible with the declaration. selfis resolved to the declaring class, andparentis resolved through the class that defines the method, so inherited methods document correctly no matter which subclass calls them.- Constructor generics and other inferred detail now flow through to the generated documentation.
- Upgrade and regenerate — the improvement lives entirely inside the analyzer, with no configuration changes required.