Last active
November 23, 2020 11:37
-
-
Save RayhanYulanda/79ec1bfe302da41666698bb0bee2759c to your computer and use it in GitHub Desktop.
User bad class
This file contains 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 | |
class User { | |
public $name; | |
public $email; | |
public function __construct($data) { | |
$this->name = $data['name']; | |
$this->email = $data['email']; | |
} | |
public function formatJson() { | |
return json_encode(['name' => $this->name, 'email' => $this->email]); | |
} | |
public function validate($data) { | |
if (!isset($data['name'])) { new \Exception("Bad Request, User Requires A Name")}; | |
if (!isset($data['email'])) { new \Exception("Bad Request, User Email Required")}; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment