Showing 718 of 718 total issues
Similar blocks of code found in 3 locations. Consider refactoring. Open
private function loadSimilarityProfiles( SearchProfileService $service, SearchConfig $config ) {
$service->registerFileRepository( SearchProfileService::SIMILARITY, self::CIRRUS_BASE,
__DIR__ . '/../../profiles/SimilarityProfiles.config.php' );
$service->registerRepository( new ConfigProfileRepository( SearchProfileService::SIMILARITY,
self::CIRRUS_CONFIG, 'CirrusSearchSimilarityProfiles', $config ) );
- 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 152.
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
File check_indices.py
has 310 lines of code (exceeds 250 allowed). Consider refactoring. Open
"""
Reconcile expected indices against live cluster state
Reconciles the state of multiple elasticsearch clusters against the expected
state of multiple wikis. The reconciliation process is accept based. Some
Function execute
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public function execute() {
$result = $this->getResult();
$services = MediaWikiServices::getInstance();
$engine = $services->getSearchEngineFactory()->create();
if ( !( $engine instanceof CirrusSearch ) ) {
- 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 execute
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
$result = $this->getResult();
$services = MediaWikiServices::getInstance();
$engine = $services->getSearchEngineFactory()->create();
if ( !( $engine instanceof CirrusSearch ) ) {
File Updater.php
has 304 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace CirrusSearch;
use CirrusSearch\BuildDocument\BuildDocument;
Method parse
has 82 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function parse( $query, KeywordFeature $feature, OffsetTracker $tracker, $startOffset = 0 ) {
if ( $feature->greedy() ) {
Assert::precondition( !$feature->allowEmptyValue(),
"greedy keywords must not accept empty value" );
// XXX: we ignore value delimiter for greedy keywords
Function deduplicateAnalysisConfig
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public function deduplicateAnalysisConfig( array $analysis ) {
// Deduplicate children first to normalize analyzer configuration.
foreach ( [ 'tokenizer', 'filter', 'char_filter' ] as $k ) {
if ( !isset( $analysis[$k] ) ) {
continue;
- 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 collectTitlesFromDB
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
private function collectTitlesFromDB( $term ) {
$titles = [];
$found = [];
$titleFactory = MediaWikiServices::getInstance()->getTitleFactory();
$wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory();
- 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
File SaneitizeJobs.php
has 301 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace CirrusSearch\Maintenance;
use CirrusSearch\Connection;
File AnalyzerBuilder.php
has 299 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace CirrusSearch\Maintenance;
use MediaWiki\Config\ConfigException;
QueryStringRegexParser
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class QueryStringRegexParser implements QueryParser {
/**
* Whitespace regex including unicode and some control chars
*/
private const WHITESPACE_REGEX = '/\G[\pZ\pC]+/u';
Function detect
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function detect( $text ) {
$dirs = $this->config->getElement( 'CirrusSearchTextcatModel' );
if ( !$dirs ) {
return 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 doJob
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
protected function doJob() {
$profile = $this->searchConfig
->getProfileService()
->loadProfileByName( SearchProfileService::SANEITIZER, $this->params['profile'], 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 parse
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function parse( string $query, int $start, int $end ) {
$match = [];
Assert::precondition( $start < $end, '$start < $end' );
Assert::precondition( $end <= strlen( $query ), '$end <= strlen( $query )' );
$ret = preg_match( self::NEGATION, $query, $match, PREG_OFFSET_CAPTURE, $start );
- 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 truncateField
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private function truncateField( string $field, bool $keyword, int $minFieldLength, int $maxDocSize, string $statBucket ): void {
if ( !$this->document->has( $field ) ) {
return;
}
$fieldData = $this->document->get( $field );
- 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
AnalysisConfigBuilder
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class AnalysisConfigBuilder {
/**
* Version number for the core analysis. Increment the major
* version when the analysis changes in an incompatible way,
* and change the minor version when it changes but isn't
UpdateSuggesterIndex
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class UpdateSuggesterIndex extends Maintenance {
/**
* @var string language code we're building for
*/
private $langCode;
Method execute
has 75 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function execute() {
$this->disablePoolCountersAndLogging();
$utils = new ConfigUtils( $this->getConnection()->getClient(), $this );
Function bulkResponseExceptionIsJustDocumentMissing
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
protected function bulkResponseExceptionIsJustDocumentMissing(
ResponseException $exception, $logCallback = null
) {
$justDocumentMissing = true;
foreach ( $exception->getResponseSet()->getBulkResponses() as $bulkResponse ) {
- 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 searchTextInternal
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
private function searchTextInternal( $term ) {
// Searcher needs to be cloned before any actual query building is done.
$interleaveSearcher = $this->buildInterleaveSearcher();
$qb = $this->buildFullTextSearch( $term );
- 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"