Skip to content

⚠️ !Breaking Change! Extend the generated models in the wrappers, remove getData() - #37

Merged
pavog merged 1 commit into
masterfrom
wrappers-extend-models
Oct 19, 2026
Merged

pavog merged 1 commit into
masterfrom
wrappers-extend-models

Conversation

@pavog

@pavog pavog commented Oct 19, 2026

Copy link
Copy Markdown
Member

The wrappers CompactProject, Project, User and Version now extend the generated models instead of wrapping them. All getters of the models can be called on the wrappers directly, so getData() is no longer needed:

// before
$name = $project->getData()->getName();

// after
$name = $project->getName();
Wrapper extends
Client\CompactProject Model\ProjectCompact
Client\Project Model\Project
Client\User Model\User
Client\Version Model\Version

ProjectPage is not changed, because it wraps the content of a page (a string) and not a model.

Name clashes

The only wrapper method with the same name as a getter of its model is getId() of Project and CompactProject. Both returned the id of the model, so the wrapper method is removed and the getter of the model is used instead. Its return type is ?int instead of int.

All other wrapper methods keep their behaviour. getSlug() stays, because the models do not have this getter.

Breaking changes

  • getData() is removed from all wrappers. Call the getters on the wrapper instead, e.g. $project->getName() instead of $project->getData()->getName(). Wrappers can be passed wherever a model is expected, because they are instances of it.
  • Project::getId() and CompactProject::getId() return ?int instead of int.
  • The protected properties holding the model ($project, $user, $version) are removed. This only affects classes that extend the wrappers.
  • The second constructor parameter is renamed to $data. This only affects code that creates wrappers with named arguments.

Tests and README

  • All uses of getData() are removed from the tests and the README.
  • A new unit test checks for every wrapper that it is an instance of its model, has no getData() method and returns the id of the model.
  • A new unit test checks that every wrapper is serialized to JSON like its model, without the client.
  • The README explains that the data is available through the getters of the wrappers.

@pavog
pavog merged commit 3ad83e4 into master Oct 19, 2026
4 checks passed
@pavog
pavog deleted the wrappers-extend-models branch October 19, 2026 13:47
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.

2 participants