BenMakesGames/PoppySeedPets

update entity properties, getters, and setters to be strongly typed; use __construct to ensure entities are newed up in a valid state

Open

#34 opened on Apr 14, 2025

 (0 comments) (0 reactions) (0 assignees)PHP (6 forks)auto 404
good first issuetech debt

Repository metrics

Stars
 (14 stars)
PR merge metrics
 (PR metrics pending)

Description

context: the make:entity is pretty good for creating and updating entities, but it allows many properties to be null, even if they shouldn't be. this can lead to bugs.

to reduce the chance of bugs, aim for objects to always be in a valid state.

todo:

  1. update entity properties, and related getter and setter, to be strongly-typed (including accounting for nullability)
  2. ensure entities are always newed up in a valid state; possibilities:
    1. add required properties to __construct - easy, works best when required properties are low
      • this option will probably cover the majority of cases
    2. make __construct private and create static factory methods - similar to above; preferable when there are multiple ways to construct an entity
    3. create a builder class (preferably with a fluent API) that assists with creating the entity - appropriate only when newing up an entity is very complex

it's totally legit to upgrade just one entity or a small group of entities in a PR; this issue will be closed when all entities are updated.

Contributor guide