Created
July 3, 2020 18:44
-
-
Save eujoy/eb7c9c4e17c9fb79585b47f00c19ee17 to your computer and use it in GitHub Desktop.
This is an automatically created builder for the user class https://gist.github.com/Angelos-Giannis/10b21950968a22a0859c1ff6527d71cf as it has been generated by using https://github.com/Angelos-Giannis/php-builder-class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types = 1); | |
namespace /** @todo define namespace */; | |
/** @todo Define dependencies for the builder (e.g. DI). */ | |
use \Example\MyClass\User; | |
class UserBuilder | |
{ | |
/** @todo Define any required private variables for the builder. */ | |
/** @var User $user */ | |
private $user; | |
public function __construct() | |
{ | |
/** @todo Define any required steps for constructor. */ | |
$this->user = new User(); | |
} | |
/** | |
* Creates the User in the database and returns it. | |
* | |
* @return User | |
*/ | |
public function build() : User | |
{ | |
$this->createUser(); | |
return $this->user; | |
} | |
/** | |
* Builds a batch of offline reasons based on a provided array of the form : | |
* [ | |
* ["id", "first_name", "last_name", "username", "password"], | |
* ["id", "first_name", "last_name", "username", "password"], | |
* ] | |
* | |
* @param array $details | |
* | |
* @return array | |
*/ | |
public function buildFromArray(array $details) : array | |
{ | |
$user_array = []; | |
foreach ($details as $dt) { | |
$user_array[] = (new self()) | |
->withId($dt[0]) | |
->withFirstName($dt[1]) | |
->withLastName($dt[2]) | |
->withUsername($dt[3]) | |
->withPassword($dt[4]) | |
->build(); | |
} | |
return $user_array; | |
} | |
/** | |
* Set the value for id. | |
* | |
* @param int $id | |
* | |
* @return UserBuilder | |
*/ | |
public function withId(int $id) : UserBuilder | |
{ | |
$this->user->id = $id; | |
return $this; | |
} | |
/** | |
* Set the value for first_name. | |
* | |
* @param string $first_name | |
* | |
* @return UserBuilder | |
*/ | |
public function withFirstName(string $first_name) : UserBuilder | |
{ | |
$this->user->first_name = $first_name; | |
return $this; | |
} | |
/** | |
* Set the value for last_name. | |
* | |
* @param string $last_name | |
* | |
* @return UserBuilder | |
*/ | |
public function withLastName(string $last_name) : UserBuilder | |
{ | |
$this->user->last_name = $last_name; | |
return $this; | |
} | |
/** | |
* Set the value for username. | |
* | |
* @param string $username | |
* | |
* @return UserBuilder | |
*/ | |
public function withUsername(string $username) : UserBuilder | |
{ | |
$this->user->username = $username; | |
return $this; | |
} | |
/** | |
* Set the value for password. | |
* | |
* @param string $password | |
* | |
* @return UserBuilder | |
*/ | |
public function withPassword(string $password) : UserBuilder | |
{ | |
$this->user->password = $password; | |
return $this; | |
} | |
/** | |
* Stores the User in the database. | |
* | |
* @return void | |
*/ | |
public function createUser() : void | |
{ | |
/** | |
* @todo Implement the object persistence function. | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment