File BlockManager.php
has 463 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
BlockManager
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class BlockManager {
/** @var UserFactory */
private $userFactory;
/** @var UserIdentityUtils */
Function inDnsBlacklist
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
private function inDnsBlacklist( $ip, array $bases ) {
$found = false;
// @todo FIXME: IPv6 ??? (https://bugs.php.net/bug.php?id=33170)
if ( IPUtils::isIPv4( $ip ) ) {
// Reverse IP, T23255
- 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 filter
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function filter( ?Block $block, $callback ) {
if ( !$block ) {
return null;
} elseif ( $block instanceof CompositeBlock ) {
$blocks = $block->getOriginalBlocks();
- 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 trackBlockWithCookie
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function trackBlockWithCookie( User $user, WebResponse $response ) {
$request = $user->getRequest();
if ( $request->getCookie( 'BlockID' ) !== null ) {
$cookieBlock = $this->getBlockFromCookieValue( $user, $request );
- 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 inDnsBlacklist
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function inDnsBlacklist( $ip, array $bases ) {
$found = false;
// @todo FIXME: IPv6 ??? (https://bugs.php.net/bug.php?id=33170)
if ( IPUtils::isIPv4( $ip ) ) {
// Reverse IP, T23255
Method getBlock
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getBlock(
UserIdentity $user,
?WebRequest $request,
$fromReplica = true
): ?AbstractBlock {
Method getCreateAccountBlock
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getCreateAccountBlock(
UserIdentity $user,
?WebRequest $request,
$fromReplica
) {
Method getSystemIpBlocks
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getSystemIpBlocks( string $ip, bool $applySoftBlocks ): array {
$blocks = [];
// Proxy blocking
if ( !in_array( $ip, $this->options->get( MainConfigNames::ProxyWhitelist ) ) ) {
Method trackBlockWithCookie
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function trackBlockWithCookie( User $user, WebResponse $response ) {
$request = $user->getRequest();
if ( $request->getCookie( 'BlockID' ) !== null ) {
$cookieBlock = $this->getBlockFromCookieValue( $user, $request );
Method __construct
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
ServiceOptions $options,
UserFactory $userFactory,
UserIdentityUtils $userIdentityUtils,
LoggerInterface $logger,
HookContainer $hookContainer,
Function getUniqueBlocks
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function getUniqueBlocks( array $blocks ) {
$systemBlocks = [];
$databaseBlocks = [];
foreach ( $blocks as $block ) {
- 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 getBlocksForIPList
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getBlocksForIPList( array $ipChain, bool $applySoftBlocks, bool $fromPrimary ) {
if ( $ipChain === [] ) {
return [];
}
- 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 getCreateAccountBlock
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getCreateAccountBlock(
UserIdentity $user,
?WebRequest $request,
$fromReplica
) {
- 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 null;
Avoid too many return
statements within this method. Open
return $block;
Avoid too many return
statements within this method. Open
return $block->withOriginalBlocks( array_values( $blocks ) );
Function getSystemIpBlocks
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function getSystemIpBlocks( string $ip, bool $applySoftBlocks ): array {
$blocks = [];
// Proxy blocking
if ( !in_array( $ip, $this->options->get( MainConfigNames::ProxyWhitelist ) ) ) {
- 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"