Skip to content

Feature/phpstan support - #12

Open
tabennett wants to merge 12 commits into
masterfrom
feature/phpstan-support
Open

tabennett wants to merge 12 commits into
masterfrom
feature/phpstan-support

Conversation

@tabennett

Copy link
Copy Markdown
Contributor

No description provided.

@tabennett
tabennett force-pushed the feature/phpstan-support branch 2 times, most recently from 1488b9a to 0da7e2f Compare October 4, 2026 05:22
@tabennett
tabennett force-pushed the feature/phpstan-support branch from 0da7e2f to a7477fd Compare November 15, 2026 07:00
- Add phpstan/phpstan ^2.2 to require-dev and autoload the
  CodeSleeve\Holloway\PhpStan\Extension namespace
- Register dynamic return type extensions so getMapper(), find(),
  get(), paginate(), and where() resolve to concrete entity and
  builder types without annotations on consumer mappers
- Add level 5 phpstan.neon covering src/ and the extension, with
  targeted ignores for SoftDeletes, legacy factories, and helpers
- Add @template TEntity and @method forward declarations so fluent
  query chains preserve the entity type
- Annotate entity, builder, and mapper methods for PHPStan level 5
- Type the $onDelete property and the Holloway singleton, and make
  nullable where()/orWhere() operators explicit
- Replace try/catch with array_key_exists in Holloway::getMapper()
- Read eager loads from the query tree in Builder::getLoads()
- Return void from customMany()/customOne() and drop makeEntity(): mixed
- Resolve getMapper() types from class constants, entity instances,
  and class-strings, including unions of entities
- Type additional forwarded methods: all, makeEntity, makeEntities,
  instantiateEntity, newCollection, newQueryWithoutScopes,
  newQueryWithoutScope, and newHollowayBuilder
- Return the union of collection and nullable entity from find()
  when the argument type cannot be narrowed
- Align Builder and Mapper @method signatures with the argument
  types Illuminate accepts (Expression, Closure, iterable, mixed)
- Assert entity, collection, paginator, and builder return types
  through TypeInferenceTestCase
- Cover getMapper() lookups by class constant, entity instance, and
  class-string, including a union of entity classes
- Add a level 8 config over the fixtures so forwarded argument
  types are validated, not just inferred return types
- Run PHPStan over src/ and the extension on PHP 8.3
- Run the level 8 fixture config to catch argument-type drift in
  forwarded @method signatures
- Install from the lock file for reproducible builds
- Add a static analysis guide covering installation, inferred types,
  registry lookups, level 6+ generics, and limitations
- Link it from the readme
- Declare extra.phpstan.includes so phpstan/extension-installer
  auto-registers the extension
- Accept anything Laravel accepts for where()/orWhere() and the pass-through
  query methods: untype the Builder::where()/orWhere() operator (it is no
  longer coerced to a string) and use variadic mixed arguments in the
  @method tags.
- Give Mapper and Builder a default template type so raw Mapper/Builder
  references (extends Mapper, a Builder parameter in a scope) don't raise
  missingType.generics.
- Return the concrete paginator classes, and drop the class-string
  annotation on getEntityClassName(), which conflicted with plain string
  implementations.
- Don't replace the return types of methods that a mapper overrides, such as
  find() or get().
- Add an overriding mapper fixture and type-inference tests for the above.
- State that no @extends annotation is needed at any level.
- Note that level 8 reports nullable find()/first() results.
- Document that scopes and soft-delete macros must be declared with @method,
  and that overridden mapper methods keep their own return types.
- Resolve scopeXxx() methods as xxx() on a concrete mapper and anywhere in a
  query chain from it, with the scope's own parameters (minus $query) checked.
  Resolve withTrashed(), withoutTrashed() and onlyTrashed() on mappers that
  use SoftDeletes.
- Give Builder a second template type, Builder<TEntity, TMapper>, which the
  extension sets wherever a builder comes from a concrete mapper. Carry it
  through the @method tags and builder return types ($this / static).
- Share the mapper-to-entity lookup between the extensions in a new
  EntityTypeResolver.
- Fall back to the @method tags for a union of mappers instead of resolving
  only the first mapper's entity.
- Ignore PHPStan's backward compatibility notice for the method reflection
  class in the project's own analysis.
- Add scope, macro and union type-inference tests and update the builder
  type expectations.
- Add a section on scopes and soft-delete macros, including what is not
  resolved (mappers from Holloway::getMapper(), bare Builder parameters).
- Note that the extension targets PHPStan 2.x.
get() takes no arguments, so get(['id', 'name']) selects every column. Point
to select() for limiting columns.
…dReflection

PHPStan 2.3 added the abstract method getPureUnlessParameterPassedParameters()
to ExtendedMethodReflection. ScopeMethodReflection implements that interface,
so with a fresh install the class failed to load with a fatal error as soon as
the type inference tests were discovered, and every job that runs the test
suite exited with 255. The interface isn't covered by PHPStan's backward
compatibility promise, which is why a minor release could add it.

Return an empty array, since nothing is known about the purity of a scope or a
soft-delete macro, the way PHPStan's own dummy reflection does. The method is
simply extra on the 2.2 interface, so older installs are unaffected.
@tabennett
tabennett force-pushed the feature/phpstan-support branch from 798f5a7 to a78190c Compare November 15, 2026 16:37
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