Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap model constructor parameters around #8

Closed
m4tthumphrey opened this issue Apr 22, 2013 · 4 comments
Closed

Swap model constructor parameters around #8

m4tthumphrey opened this issue Apr 22, 2013 · 4 comments

Comments

@m4tthumphrey
Copy link
Contributor

IE

$project = new Project($client, 1);

instead of

$project = new Project(1, $client);

This would make $client mandatory but it is always passed anyway so do not see any disadvantages to this.

@m4tthumphrey
Copy link
Contributor Author

Another alternative is to get rid of non dependencies from constructors. Ie something like

$project = new Project($client);
$project->load(1);

etc...

Edit: I like this better.

@ls12styler
Copy link

I would agree on switching the arguments order. However I would still leave the current params in, but have them as optional

public function __construct(Client $client, $id = null, $data = [])

This gives the ability to create a Model instance with great flexibility over how/when you fetch/override the data.

I would also suggest that each Model has it's own hydrate method so we can remove the logic of (in the example of Project) the User::fromArray/ProjectNamespaces::fromArray calls out of the constructor.

@ls12styler ls12styler mentioned this issue Oct 13, 2014
@ls12styler
Copy link

I would also suggest this happens before the next re tagging, since it would be a major bump and breaking changes are acceptable.

This was referenced Oct 13, 2014
@m4tthumphrey m4tthumphrey modified the milestone: 8.0 Feb 18, 2015
@GrahamCampbell GrahamCampbell removed this from the Internals milestone Jul 3, 2020
@GrahamCampbell
Copy link
Member

I think the plan is to remove models (eventually). We can close this off for now, since any refactoring tasks relating to models is not going to be worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants