File AuthManager.php
has 1809 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Authentication (and possibly Authorization in the future) system entry point
*
* This program is free software; you can redistribute it and/or modify
Method continueAccountCreation
has 326 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function continueAccountCreation( array $reqs ) {
$session = $this->request->getSession();
try {
if ( !$this->canCreateAccounts() ) {
// Caller should have called canCreateAccounts()
Method continueAuthentication
has 279 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function continueAuthentication( array $reqs ) {
$session = $this->request->getSession();
try {
if ( !$session->canSetUser() ) {
// Caller should have called canAuthenticateNow()
Function continueAuthentication
has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring. Open
public function continueAuthentication( array $reqs ) {
$session = $this->request->getSession();
try {
if ( !$session->canSetUser() ) {
// Caller should have called canAuthenticateNow()
- 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 continueAccountCreation
has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring. Open
public function continueAccountCreation( array $reqs ) {
$session = $this->request->getSession();
try {
if ( !$this->canCreateAccounts() ) {
// Caller should have called canCreateAccounts()
- 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 autoCreateUser
has 200 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function autoCreateUser(
User $user,
$source,
$login = true,
$log = true,
AuthManager
has 44 functions (exceeds 20 allowed). Consider refactoring. Open
class AuthManager implements LoggerAwareInterface {
/**
* @internal
* Key in the user's session data for storing login state.
*/
Function autoCreateUser
has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring. Open
public function autoCreateUser(
User $user,
$source,
$login = true,
$log = 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
Method beginAuthentication
has 88 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function beginAuthentication( array $reqs, $returnToUrl ) {
$session = $this->request->getSession();
if ( !$session->canSetUser() ) {
// Caller should have called canAuthenticateNow()
$session->remove( self::AUTHN_STATE );
Method beginAccountLink
has 85 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function beginAccountLink( User $user, array $reqs, $returnToUrl ) {
$session = $this->request->getSession();
$session->remove( self::ACCOUNT_LINK_STATE );
if ( !$this->canLinkAccounts() ) {
Method beginAccountCreation
has 80 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function beginAccountCreation( Authority $creator, array $reqs, $returnToUrl ) {
$session = $this->request->getSession();
if ( !$this->canCreateAccounts() ) {
// Caller should have called canCreateAccounts()
$session->remove( self::ACCOUNT_CREATION_STATE );
Method continueAccountLink
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function continueAccountLink( array $reqs ) {
$session = $this->request->getSession();
try {
if ( !$this->canLinkAccounts() ) {
// Caller should have called canLinkAccounts()
Function beginAuthentication
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public function beginAuthentication( array $reqs, $returnToUrl ) {
$session = $this->request->getSession();
if ( !$session->canSetUser() ) {
// Caller should have called canAuthenticateNow()
$session->remove( self::AUTHN_STATE );
- 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 securitySensitiveOperationStatus
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public function securitySensitiveOperationStatus( $operation ) {
$status = self::SEC_OK;
$this->logger->debug( __METHOD__ . ": Checking $operation" );
- 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 securitySensitiveOperationStatus
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function securitySensitiveOperationStatus( $operation ) {
$status = self::SEC_OK;
$this->logger->debug( __METHOD__ . ": Checking $operation" );
Function getAuthenticationRequestsInternal
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private function getAuthenticationRequestsInternal(
$providerAction, array $options, array $providers, UserIdentity $user = null
) {
$user = $user ?: RequestContext::getMain()->getUser();
$options['username'] = $user->isRegistered() ? $user->getName() : null;
- 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 beginAccountLink
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function beginAccountLink( User $user, array $reqs, $returnToUrl ) {
$session = $this->request->getSession();
$session->remove( self::ACCOUNT_LINK_STATE );
if ( !$this->canLinkAccounts() ) {
- 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 __construct
has 15 arguments (exceeds 4 allowed). Consider refactoring. Open
WebRequest $request,
Config $config,
ObjectFactory $objectFactory,
HookContainer $hookContainer,
ReadOnlyMode $readOnlyMode,
Method getAuthenticationRequests
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAuthenticationRequests( $action, UserIdentity $user = null ) {
$options = [];
$providerAction = $action;
// Figure out which providers to query
Function beginAccountCreation
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function beginAccountCreation( Authority $creator, array $reqs, $returnToUrl ) {
$session = $this->request->getSession();
if ( !$this->canCreateAccounts() ) {
// Caller should have called canCreateAccounts()
$session->remove( self::ACCOUNT_CREATION_STATE );
- 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 getAuthenticationRequestsInternal
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getAuthenticationRequestsInternal(
$providerAction, array $options, array $providers, UserIdentity $user = null
) {
$user = $user ?: RequestContext::getMain()->getUser();
$options['username'] = $user->isRegistered() ? $user->getName() : null;
Method forcePrimaryAuthenticationProviders
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function forcePrimaryAuthenticationProviders( array $providers, $why ) {
$this->logger->warning( "Overriding AuthManager primary authn because $why" );
if ( $this->primaryAuthenticationProviders !== null ) {
$this->logger->warning(
Method canCreateAccount
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function canCreateAccount( $username, $options = [] ) {
// Back compat
if ( is_int( $options ) ) {
$options = [ 'flags' => $options ];
}
Function getAuthenticationRequests
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function getAuthenticationRequests( $action, UserIdentity $user = null ) {
$options = [];
$providerAction = $action;
// Figure out which providers to query
- 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 canCreateAccount
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function canCreateAccount( $username, $options = [] ) {
// Back compat
if ( is_int( $options ) ) {
$options = [ 'flags' => $options ];
}
- 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 continueAccountLink
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function continueAccountLink( array $reqs ) {
$session = $this->request->getSession();
try {
if ( !$this->canLinkAccounts() ) {
// Caller should have called canLinkAccounts()
- 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 autoCreateUser
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
User $user,
$source,
$login = true,
$log = true,
?Authority $performer = null
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return Status::newGood();
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $this->continueAccountCreation( $reqs );
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return Status::wrap( $status );
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return Status::newFatal( 'authmanager-autocreate-exception' );
Avoid too many return
statements within this method. Open
return Status::newGood();
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $status;
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return Status::newFatal( 'usernameinprogress' );
Avoid too many return
statements within this method. Open
return $ret;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return Status::newFatal( 'noname' );
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return $res;
Avoid too many return
statements within this method. Open
return Status::wrap( $status );
Function forcePrimaryAuthenticationProviders
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function forcePrimaryAuthenticationProviders( array $providers, $why ) {
$this->logger->warning( "Overriding AuthManager primary authn because $why" );
if ( $this->primaryAuthenticationProviders !== null ) {
$this->logger->warning(
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
case AuthenticationResponse::FAIL:
$this->logger->debug( "Login failed in primary authentication by $id" );
if ( $res->createRequest || $state['maybeLink'] ) {
$res->createRequest = new CreateFromLoginAuthenticationRequest(
$res->createRequest, $state['maybeLink']
- 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 141.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
case AuthenticationResponse::FAIL:
$this->logger->debug( "Login failed in primary authentication by $id" );
if ( $res->createRequest || $state['maybeLink'] ) {
$res->createRequest = new CreateFromLoginAuthenticationRequest(
$res->createRequest, $state['maybeLink']
- 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 141.
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 3 locations. Consider refactoring. Open
public function __construct(
WebRequest $request,
Config $config,
ObjectFactory $objectFactory,
HookContainer $hookContainer,
- 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 106.
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
if ( $user->isRegistered() ) {
$this->logger->debug( __METHOD__ . ': User exists locally', [
'user' => $user->getName(),
'creator' => $creator->getName(),
] );
- 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 97.
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
if ( $state['primary'] === null ) {
$this->logger->debug( __METHOD__ . ': Primary creation failed because no provider accepted', [
'user' => $user->getName(),
'creator' => $creator->getName(),
] );
- 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 97.
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