extract getting data to private method
This commit is contained in:
parent
a64a2103e1
commit
c908381d1e
1 changed files with 8 additions and 1 deletions
|
|
@ -6,10 +6,17 @@ class FlatFileUserRepository implements UserRepository
|
||||||
{
|
{
|
||||||
private string $pathToUserFile = __DIR__.'/../../storage/users.json';
|
private string $pathToUserFile = __DIR__.'/../../storage/users.json';
|
||||||
|
|
||||||
public function findByEmail(string $email): ?User
|
private function getUserData(): array
|
||||||
{
|
{
|
||||||
$json = file_get_contents($this->pathToUserFile);
|
$json = file_get_contents($this->pathToUserFile);
|
||||||
$data = json_decode($json, true);
|
$data = json_decode($json, true);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findByEmail(string $email): ?User
|
||||||
|
{
|
||||||
|
$data = $this->getUserData();
|
||||||
foreach ($data as $user) {
|
foreach ($data as $user) {
|
||||||
if ($user['email'] === $email) {
|
if ($user['email'] === $email) {
|
||||||
return new User($user['email'], $user['password']);
|
return new User($user['email'], $user['password']);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue