3
\$\begingroup\$

This function checks these 6 fields for a user profile to determine if they have "completed" their profile. This just feels like it could be done better, but I can't figure how.

/**
 * Is the user's entire profile filled in?
 *
 * @return boolean
 */
public function isProfileComplete()
{
 $checkList = [
 $this->isAddressGiven(),
 $this->isGenderSelected(),
 null !== $this->getFirstName(),
 null !== $this->getLastName(),
 null !== $this->getJobTitle(),
 null !== $this->getAboutMe(),
 ];
 // If any one of the checks fails, profile is missing information
 foreach ($checkList as $checkItem) {
 if (!$checkItem) {
 return false;
 }
 }
 return true;
}
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Aug 7, 2015 at 16:46
\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

There's no sense in creating a dynamic array for a fixed set of checks. Just put them in a single boolean expression.

public function isProfileComplete()
{
 return $this->isAddressGiven()
 && $this->isGenderSelected()
 && null !== $this->getFirstName()
 && null !== $this->getLastName()
 && null !== $this->getJobTitle() 
 && null !== $this->getAboutMe()
 ;
}
answered Aug 7, 2015 at 19:31
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.