Skip to content

Commit

Permalink
chore(php): Run composer run cs:fix
Browse files Browse the repository at this point in the history
Signed-off-by: Baptiste Fotia <[email protected]>
  • Loading branch information
zak39 committed Feb 14, 2024
1 parent 6021377 commit 805b4c2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 93 deletions.
88 changes: 44 additions & 44 deletions lib/Controller/FileCSVController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,32 +137,32 @@ public function import(): JSONResponse {

$uids = array_map(fn ($user) => $user->uid, $usersFormatted);

$emails = array_values(
array_filter(
$uids,
fn($uid) => filter_var($uid, FILTER_VALIDATE_EMAIL)
)
);
$emails = array_values(
array_filter(
$uids,
fn ($uid) => filter_var($uid, FILTER_VALIDATE_EMAIL)
)
);

$usernames = array_values(
array_diff($uids, $emails)
);
$usernames = array_values(
array_diff($uids, $emails)
);

if (!$this->userChecker->checkUsersExist($usernames)
|| !$this->userChecker->checkUsersExistByEmail($emails)) {
|| !$this->userChecker->checkUsersExistByEmail($emails)) {
$usernamesUnknown = array_filter(
$usernames,
function ($name) {
return !$this->userChecker->checkUserExist($name);
}
);

$emailsUnknown = array_filter(
$emails,
fn ($email) => !$this->userChecker->checkUserExistByEmail($email)
);
$emailsUnknown = array_filter(
$emails,
fn ($email) => !$this->userChecker->checkUserExistByEmail($email)
);

$usersUnknown = array_merge($usernamesUnknown, $emailsUnknown);
$usersUnknown = array_merge($usernamesUnknown, $emailsUnknown);

$usersUnknown = array_slice($usersUnknown, 0, 10);
$usersUnknown[] = '...';
Expand All @@ -183,13 +183,13 @@ function ($name) {

$data = [];
foreach($usersFormatted as $user) {
$uid = $user->uid;
$uid = $user->uid;

if ($this->userChecker->checkUserExistByEmail($uid)) {
$uid = $this->userManager->getByEmail($user->uid)[0];
} else {
$uid = $this->userManager->get($user->uid);
}
if ($this->userChecker->checkUserExistByEmail($uid)) {
$uid = $this->userManager->getByEmail($user->uid)[0];
} else {
$uid = $this->userManager->get($user->uid);
}

$data[] = [
'user' => $uid,
Expand Down Expand Up @@ -290,33 +290,33 @@ public function getFromFiles():JSONResponse {

$uids = array_map(fn ($user) => $user->uid, $names);

$emails = array_values(
array_filter(
$uids,
fn($uid) => filter_var($uid, FILTER_VALIDATE_EMAIL)
)
);
$emails = array_values(
array_filter(
$uids,
fn ($uid) => filter_var($uid, FILTER_VALIDATE_EMAIL)
)
);

$usernames = array_values(
array_diff($uids, $emails)
);
$usernames = array_values(
array_diff($uids, $emails)
);

if (!$this->userChecker->checkUsersExist($usernames)
|| !$this->userChecker->checkUsersExistByEmail($emails)) {
if (!$this->userChecker->checkUsersExist($usernames)
|| !$this->userChecker->checkUsersExistByEmail($emails)) {

$usernamesUnknown = array_filter(
$usernamesUnknown = array_filter(
$usernames,
function ($name) {
return !$this->userChecker->checkUserExist($name);
}
);

$emailsUnknown = array_filter(
$emails,
fn ($email) => !$this->userChecker->checkUserExistByEmail($email)
);
$emailsUnknown = array_filter(
$emails,
fn ($email) => !$this->userChecker->checkUserExistByEmail($email)
);

$usersUnknown = array_merge($usernamesUnknown, $emailsUnknown);
$usersUnknown = array_merge($usernamesUnknown, $emailsUnknown);

$usersUnknown = array_slice($usersUnknown, 0, 10);
$usersUnknown[] = '...';
Expand All @@ -337,13 +337,13 @@ function ($name) {

$data = [];
foreach($names as $user) {
$uid = $user->uid;
$uid = $user->uid;

if ($this->userChecker->checkUserExistByEmail($uid)) {
$uid = $this->userManager->getByEmail($user->uid)[0];
} else {
$uid = $this->userManager->get($user->uid);
}
if ($this->userChecker->checkUserExistByEmail($uid)) {
$uid = $this->userManager->getByEmail($user->uid)[0];
} else {
$uid = $this->userManager->get($user->uid);
}

$data[] = [
'user' => $uid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ public function __construct(private string $title, string $message, int $code =
parent::__construct($title, $message, $code);
}
}

95 changes: 47 additions & 48 deletions lib/Users/UsersExistCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace OCA\Workspace\Users;

use OCA\Workspace\Exceptions\Notifications\EmailDoesntUniqueException;
use OCP\IL10N;
use OCP\IUserManager;
use OCA\Workspace\Exceptions\Notifications\EmailDoesntUniqueException;

class UsersExistCheck {
public function __construct(private IUserManager $userManager, private IL10N $translate) {
Expand Down Expand Up @@ -33,53 +33,52 @@ public function checkUserExist(string $name): bool {
return $this->userManager->userExists($name);
}

public function checkUserExistByEmail(string $email): bool
{
$userEmail = $this->userManager->getByEmail($email);

if (count($userEmail) > 1) {
$message = $this->translate->t(
'The %s email address is duplicated in your instance.'
. ' Impossible to know which users choice or maybe is'
. ' an error.',
$email
);
throw new EmailDoesntUniqueException(
'Email address doesn\'t unique',
$message
);
}
public function checkUserExistByEmail(string $email): bool {
$userEmail = $this->userManager->getByEmail($email);

if (count($userEmail) > 1) {
$message = $this->translate->t(
'The %s email address is duplicated in your instance.'
. ' Impossible to know which users choice or maybe is'
. ' an error.',
$email
);
throw new EmailDoesntUniqueException(
'Email address doesn\'t unique',
$message
);
}

if (!$userEmail) {
return false;
}
return true;
}
public function checkUsersExistByEmail(array $emails): bool {
if (!$userEmail) {
return false;
}
return true;
}
public function checkUsersExistByEmail(array $emails): bool {

foreach ($emails as $email) {
$userEmail = $this->userManager->getByEmail($email);
if (count($userEmail) > 1) {
$message = $this->translate->t(
'The %s email address is duplicated in your instance.'
. ' Impossible to know which users choice or maybe is'
. ' an error.',
$email
);
throw new EmailDoesntUniqueException(
'Email address doesn\'t unique',
$message
);
}
if (!$userEmail) {
return false;
}
}
return true;
}
foreach ($emails as $email) {
$userEmail = $this->userManager->getByEmail($email);
if (count($userEmail) > 1) {
$message = $this->translate->t(
'The %s email address is duplicated in your instance.'
. ' Impossible to know which users choice or maybe is'
. ' an error.',
$email
);
throw new EmailDoesntUniqueException(
'Email address doesn\'t unique',
$message
);
}
if (!$userEmail) {
return false;
}
}
return true;
}
}

0 comments on commit 805b4c2

Please sign in to comment.