File WikiImporter.php
has 855 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* MediaWiki page data importer.
*
* Copyright © 2003,2005 Brooke Vibber <bvibber@wikimedia.org>
WikiImporter
has 51 functions (exceeds 20 allowed). Consider refactoring. Open
class WikiImporter {
/** @var XMLReader|null */
private $reader;
/** @var string */
Function handlePage
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
private function handlePage() {
// Handle page data.
$this->debug( "Enter page handler." );
$pageInfo = [ 'revisionCount' => 0, 'successfulRevisionCount' => 0 ];
- 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 doImport
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
public function doImport() {
$this->syntaxCheckXML();
// Calls to reader->read need to be wrapped in calls to
// libxml_disable_entity_loader() to avoid local file
- 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 doImport
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doImport() {
$this->syntaxCheckXML();
// Calls to reader->read need to be wrapped in calls to
// libxml_disable_entity_loader() to avoid local file
Function handleUpload
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
private function handleUpload( &$pageInfo ) {
$this->debug( "Enter upload handler" );
$uploadInfo = [];
$normalFields = [ 'timestamp', 'comment', 'filename', 'text',
- 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 handlePage
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handlePage() {
// Handle page data.
$this->debug( "Enter page handler." );
$pageInfo = [ 'revisionCount' => 0, 'successfulRevisionCount' => 0 ];
Method handleUpload
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleUpload( &$pageInfo ) {
$this->debug( "Enter upload handler" );
$uploadInfo = [];
$normalFields = [ 'timestamp', 'comment', 'filename', 'text',
Method processRevision
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function processRevision( $pageInfo, $revisionInfo ) {
$revision = new WikiRevision();
$revId = $revisionInfo['id'] ?? 0;
if ( $revId ) {
Function handleRevision
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private function handleRevision( &$pageInfo ) {
$this->debug( "Enter revision handler" );
$revisionInfo = [];
$normalFields = [ 'id', 'parentid', 'timestamp', 'comment', 'minor', 'origin',
- 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 11 arguments (exceeds 4 allowed). Consider refactoring. Open
ImportSource $source,
Authority $performer,
Config $config,
HookContainer $hookContainer,
Language $contentLanguage,
Method processUpload
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function processUpload( $pageInfo, $uploadInfo ) {
$revision = new WikiRevision();
$revId = $pageInfo['id'];
$title = $pageInfo['_title'];
// T292348: text key may be absent, force addition if null
Method setTargetRootPage
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setTargetRootPage( $rootpage ) {
$status = Status::newGood();
$nsInfo = $this->namespaceInfo;
if ( $rootpage === null ) {
// No rootpage
Method processLogItem
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function processLogItem( $logInfo ) {
$revision = new WikiRevision();
if ( isset( $logInfo['id'] ) ) {
$revision->setID( $logInfo['id'] );
Method handleRevision
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function handleRevision( &$pageInfo ) {
$this->debug( "Enter revision handler" );
$revisionInfo = [];
$normalFields = [ 'id', 'parentid', 'timestamp', 'comment', 'minor', 'origin',
Method processTitle
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function processTitle( $text, $ns = null ) {
if ( $this->foreignNamespaces === null ) {
$foreignTitleFactory = new NaiveForeignTitleFactory(
$this->contentLanguage
);
Method makeContent
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function makeContent( Title $title, $revisionId, $contentInfo ) {
$maxArticleSize = $this->config->get( MainConfigNames::MaxArticleSize );
if ( !isset( $contentInfo['text'] ) ) {
throw new InvalidArgumentException( 'Missing text field in import.' );
Function processRevision
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function processRevision( $pageInfo, $revisionInfo ) {
$revision = new WikiRevision();
$revId = $revisionInfo['id'] ?? 0;
if ( $revId ) {
- 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 handleLogItem
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function handleLogItem() {
$this->debug( "Enter log item handler." );
$logInfo = [];
// Fields that can just be stuffed in the pageInfo object
- 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 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct(
ImportSource $source,
Authority $performer,
Config $config,
HookContainer $hookContainer,
Function handleContent
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private function handleContent() {
$this->debug( "Enter content handler" );
$contentInfo = [];
$normalFields = [ 'role', 'origin', 'model', 'format', 'text' ];
- 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 handleSiteInfo
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function handleSiteInfo() {
$this->debug( "Enter site info handler." );
$siteInfo = [];
// Fields that can just be stuffed in the siteInfo object
- 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 handleContributor
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function handleContributor() {
$this->debug( "Enter contributor handler." );
if ( $this->reader->isEmptyElement ) {
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 finishImportPage
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function finishImportPage( PageIdentity $pageIdentity, $foreignTitle, $revCount,
$sRevCount, $pageInfo
) {
// Update article count statistics (T42009)
// The normal counting logic in WikiPage->doEditUpdates() is designed for
- 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 processLogItem
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function processLogItem( $logInfo ) {
$revision = new WikiRevision();
if ( isset( $logInfo['id'] ) ) {
$revision->setID( $logInfo['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 pageOutCallback
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function pageOutCallback( PageIdentity $pageIdentity, $foreignTitle, $revCount,
$sucCount, $pageInfo ) {
Method finishImportPage
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function finishImportPage( PageIdentity $pageIdentity, $foreignTitle, $revCount,
$sRevCount, $pageInfo
Function setTargetRootPage
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function setTargetRootPage( $rootpage ) {
$status = Status::newGood();
$nsInfo = $this->namespaceInfo;
if ( $rootpage === null ) {
// No rootpage
- 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 [ $title, $foreignTitle ];
Function openReader
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function openReader() {
// Enable the entity loader, as it is needed for loading external URLs via
// XMLReader::open (T86036)
// phpcs:ignore Generic.PHP.NoSilencedErrors -- suppress deprecation per T268847
$oldDisable = @libxml_disable_entity_loader( false );
- 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 processTitle
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function processTitle( $text, $ns = null ) {
if ( $this->foreignNamespaces === null ) {
$foreignTitleFactory = new NaiveForeignTitleFactory(
$this->contentLanguage
);
- 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
if ( isset( $revisionInfo['contributor']['username'] ) ) {
$revision->setUsername(
$this->externalUserNames->applyPrefix( $revisionInfo['contributor']['username'] )
);
} elseif ( isset( $revisionInfo['contributor']['ip'] ) ) {
- 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 91.
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 ( isset( $logInfo['contributor']['username'] ) ) {
$revision->setUsername(
$this->externalUserNames->applyPrefix( $logInfo['contributor']['username'] )
);
} elseif ( isset( $logInfo['contributor']['ip'] ) ) {
- 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 91.
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