File UsersController.php
has 974 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Clark Tomlinson <fallen013@gmail.com>
* @author Joas Schilling <coding@schilljs.com>
Function create
has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring. Open
public function create($username, $password, array $groups= [], $email='') {
$resp = $this->validateString($username, 255);
if ($resp) {
return $resp;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function index
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
// FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
if ($gid === '_everyone') {
$gid = '';
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create
has 96 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function create($username, $password, array $groups= [], $email='') {
$resp = $this->validateString($username, 255);
if ($resp) {
return $resp;
}
Method setMailAddress
has 92 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setMailAddress($id, $mailAddress) {
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
if ($userId !== $id
UsersController
has 24 functions (exceeds 20 allowed). Consider refactoring. Open
class UsersController extends Controller {
/** @var IL10N */
private $l10n;
/** @var Session */
private $userSession;
Method setPassword
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setPassword($token, $userId, $password) {
$user = $this->userManager->get($userId);
if ($user === null) {
$this->log->error('User: ' . $userId . ' does not exist.', ['app' => 'settings']);
Method index
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
// FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
if ($gid === '_everyone') {
$gid = '';
}
Method __construct
has 18 arguments (exceeds 4 allowed). Consider refactoring. Open
$appName,
IRequest $request,
IUserManager $userManager,
IGroupManager $groupManager,
Session $userSession,
Method formatUserForIndex
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function formatUserForIndex(IUser $user, array $userGroups = null) {
// TODO: eliminate this encryption specific code below and somehow
// hook in additional user info from other apps
// recovery isn't possible if admin or user has it disabled and encryption
Method setEnabled
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setEnabled($id, $enabled) {
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
'@phan-var \OC\Group\Manager $this->groupManager';
Method resendInvitation
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function resendInvitation($userId) {
$user = $this->userManager->get($userId);
$currentUser = $this->userSession->getUser();
if ($user === null || $this->userTypeHelper->isGuestUser($userId) === true) {
Method destroy
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function destroy($id) {
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
if ($userId === $id) {
Method setDisplayName
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setDisplayName($username, $displayName) {
$resp = $this->validateString($displayName, 64);
if ($resp) {
return $resp;
}
Method resendToken
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function resendToken($userId) {
$user = $this->userManager->get($userId);
if ($user === null) {
$this->log->error('User: ' . $userId . ' does not exist', ['app' => 'settings']);
Function stats
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function stats() {
$userCount = 0;
if ($this->isAdmin) {
$countByBackend = $this->userManager->countUsers();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function setMailAddress
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function setMailAddress($id, $mailAddress) {
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
if ($userId !== $id
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method changeMail
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function changeMail($token, $userId) {
$user = $this->userManager->get($userId);
$sessionUser = $this->userSession->getUser();
if ($user->getUID() !== $sessionUser->getUID()) {
Method sendEmail
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function sendEmail($userId, $mailAddress) {
$token = $this->config->getUserValue($userId, 'owncloud', 'changeMail');
if ($token !== '') {
$splittedToken = \explode(':', $token);
if ((\count($splittedToken)) === 3 && $splittedToken[0] > ($this->timeFactory->getTime() - 60 * 5)) {
Method setPasswordForm
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setPasswordForm($token, $userId) {
try {
$this->checkPasswordSetToken($token, $userId);
} catch (UserTokenException $e) {
if ($e instanceof UserTokenExpiredException) {
Method generateTokenAndSendMail
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function generateTokenAndSendMail($userId, $email) {
$token = $this->secureRandom->generate(
21,
ISecureRandom::CHAR_DIGITS,
ISecureRandom::CHAR_LOWER,
Function formatUserForIndex
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function formatUserForIndex(IUser $user, array $userGroups = null) {
// TODO: eliminate this encryption specific code below and somehow
// hook in additional user info from other apps
// recovery isn't possible if admin or user has it disabled and encryption
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function setEmailAddress
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function setEmailAddress($id, $mailAddress) {
$resp = $this->validateEMail($mailAddress);
if ($resp) {
return $resp;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method index
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
Function setDisplayName
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function setDisplayName($username, $displayName) {
$resp = $this->validateString($displayName, 64);
if ($resp) {
return $resp;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function resendInvitation
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function resendInvitation($userId) {
$user = $this->userManager->get($userId);
$currentUser = $this->userSession->getUser();
if ($user === null || $this->userTypeHelper->isGuestUser($userId) === true) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return new JSONResponse(
["error" => $this->l10n->t('Can\'t send email to the user. Contact your administrator.')],
HTTP::STATUS_INTERNAL_SERVER_ERROR
);
Avoid too many return
statements within this method. Open
return new JSONResponse(
[
'status' => 'error',
'message' => $this->l10n->t('Failed to send email. Please contact your administrator.'),
'type' => 'emailsendfailed'
Avoid too many return
statements within this method. Open
return new JSONResponse(['status' => 'success']);
Avoid too many return
statements within this method. Open
return new DataResponse(
[
'status' => 'error',
'data' => [
'message' => (string)$e->getMessage()
Avoid too many return
statements within this method. Open
return new DataResponse(
[
'status' => 'success',
'data' => [
'username' => $id,
Avoid too many return
statements within this method. Open
return new DataResponse(
[
'message' => (string)$this->l10n->t('Unable to create user.')
],
Http::STATUS_FORBIDDEN
Avoid too many return
statements within this method. Open
return new DataResponse(
[
'status' => 'error',
'data' => [
'username' => $id,
Avoid too many return
statements within this method. Open
return new JSONResponse();
Avoid too many return
statements within this method. Open
return new DataResponse(
$this->formatUserForIndex($user, $userGroups),
Http::STATUS_CREATED
);
Avoid too many return
statements within this method. Open
return new DataResponse(
[
'status' => 'success',
'data' => [
'message' => (string)$this->l10n->t('Email has been changed successfully.')
Function setEnabled
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function setEnabled($id, $enabled) {
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
'@phan-var \OC\Group\Manager $this->groupManager';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function changeMail
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function changeMail($token, $userId) {
$user = $this->userManager->get($userId);
$sessionUser = $this->userSession->getUser();
if ($user->getUID() !== $sessionUser->getUID()) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function destroy
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function destroy($id) {
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
if ($userId === $id) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
try {
$message = $this->mailer->createMessage();
$message->setTo([$oldEmailAddress => $userId]);
$message->setSubject($this->l10n->t('%s email address changed successfully', [$this->defaults->getName()]));
$message->setPlainBody($msg);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 126.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
try {
$message = $this->mailer->createMessage();
$message->setTo([$mailAddress => $userId]);
$message->setSubject($this->l10n->t('%s email address confirm', [$this->defaults->getName()]));
$message->setPlainBody($msg);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 126.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76