Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • What is the relationship between User and Company? Can a User be part of zero or more Companies? Commented Dec 5, 2021 at 20:12
  • currently the user can be the part of only one company not more than one or zero Commented Dec 6, 2021 at 3:25
  • You shouldn't ask what the state of the company is - that's internal to the company object, it's an internal representation that should be invisible to you ("you" meaning the calling code). You should ask the company object to attempt a login, let it internally process the request & determine how to respond based on its state, before returning control back to the caller. The caller can then decide how to deal with the response. Remember - write things in terms of communicating encapsulated objects. Commented Dec 6, 2021 at 12:30
  • If you mean to this: $company->state->login(); along with $user->state->login(); then it doesn't make sense to me. Because a user can login but a company cannot login. But the state of the company along with the state of the user decides if the user should login or not. Can you please explain with code? Commented Dec 7, 2021 at 2:18
  • No, there's no interaction/communication there. Depends on what else you're doing, but one way would be $company->attemptLogin($credentials, 'callbackOnSuccess', callbackOnFailure'), where the success callback could accept the token and do something with it, and the failure callback could accept an object (or just a string) describing why login failed. Or, instead of a callback, you could pass a full-blown object to call methods on. Or if that doesn't quite work, adjust the design, maybe introduce an intermediate object that you can call, then reveal state to it, but not to the callers. Commented Dec 7, 2021 at 7:28