wikimedia/mediawiki-extensions-CirrusSearch

View on GitHub

Showing 718 of 718 total issues

Function execute has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function execute() {
        $this->disablePoolCountersAndLogging();
        $profiles = [];
        $profileService = $this->getSearchConfig()->getProfileService();
        if ( $this->hasOption( 'profile' ) ) {
Severity: Minor
Found in maintenance/UpdateDYMIndexTemplates.php - About 1 hr to fix

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 execute has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function execute() {
        if ( $this->hasOption( 'nagios' ) ) {
            // Force silent running mode so we can match Nagios expected output.
            $this->mQuiet = true;
        }
Severity: Minor
Found in maintenance/CheckIndexes.php - About 1 hr to fix

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 retry has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function retry( $cause, $newFrom, $cluster = null ) {
        if ( $this->params['retryCount'] >= self::JOB_MAX_RETRIES ) {
            LoggerFactory::getInstance( 'CirrusSearch' )->info(
                "Sanitize CheckerJob: $cause ({fromPageId}:{toPageId}), Abandonning CheckerJob after {retries} retries " .
                "for {cluster}, (jobs_chunk_size too high?).",
Severity: Minor
Found in includes/Job/CheckerJob.php - About 1 hr to fix

    Method switchAliasTo has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function switchAliasTo( $index ) {
            $name = $index->getName();
            $oldIndexName = $this->getAliasedIndexName();
            if ( $oldIndexName !== null ) {
                $this->log( "Switching " . self::INDEX_NAME . " alias from $oldIndexName to $name.\n" );
    Severity: Minor
    Found in includes/MetaStore/MetaStoreIndex.php - About 1 hr to fix

      Method suggest has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function suggest( $text, $variants = null ) {
              $suggestSearch = $this->getSuggestSearchRequest( $text, $variants );
              $mSearchRequests = new MSearchRequests();
      
              if ( $suggestSearch !== null ) {
      Severity: Minor
      Found in includes/CompletionSuggester.php - About 1 hr to fix

        Method buildRegexWithGroovy has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function buildRegexWithGroovy( $pattern, $insensitive ) {
                $filters = [];
                foreach ( $this->fields as $field ) {
                    $script = <<<GROOVY
        import org.apache.lucene.util.automaton.*;
        Severity: Minor
        Found in includes/Query/BaseRegexFeature.php - About 1 hr to fix

          Method explainTemplateBoosts has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function explainTemplateBoosts( array $doc ) {
                  if ( !isset( $doc['template'] ) ) {
                      return [
                          'value' => 1,
                          'description' => 'No templates'
          Severity: Minor
          Found in includes/BuildDocument/Completion/QualityScore.php - About 1 hr to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                'wsum_inclinks_pv' => [
                    'i18n_msg' => 'cirrussearch-qi-profile-wsum-inclinks-pv',
                    'supported_namespaces' => 'content',
                    'fallback_profile' => 'wsum_inclinks',
                    'rescore' => [
            Severity: Major
            Found in profiles/RescoreProfiles.config.php and 1 other location - About 1 hr to fix
            profiles/RescoreProfiles.config.php on lines 177..202

            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 108.

            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

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                'popular_inclinks_pv' => [
                    'supported_namespaces' => 'content',
                    'fallback_profile' => 'popular_inclinks',
                    'i18n_msg' => 'cirrussearch-qi-profile-popular-pv',
                    'rescore' => [
            Severity: Major
            Found in profiles/RescoreProfiles.config.php and 1 other location - About 1 hr to fix
            profiles/RescoreProfiles.config.php on lines 147..172

            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 108.

            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

            Further Reading

            Method getHighlightingConfiguration has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getHighlightingConfiguration( array $extraHighlightFields = [] ) {
                    global $wgCirrusSearchUseExperimentalHighlighter;
            
                    if ( $wgCirrusSearchUseExperimentalHighlighter ) {
                        // This is much less esoteric then the plain highlighter based
            Severity: Minor
            Found in includes/Search/FancyTitleResultsType.php - About 1 hr to fix

              Method validate has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function validate(): Status {
                      // arrays of aliases to be added/removed
                      $add = $remove = [];
              
                      $this->outputIndented( "\tValidating $this->aliasName alias..." );
              Severity: Minor
              Found in includes/Maintenance/Validators/IndexAliasValidator.php - About 1 hr to fix

                Method __construct has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function __construct(
                        SearchConfig $config,
                        CirrusSearchHookRunner $cirrusSearchHookRunner = null,
                        NamespacePrefixParser $namespacePrefixParser = null,
                        SparqlClient $client = null
                Severity: Minor
                Found in includes/Parser/FullTextKeywordRegistry.php - About 1 hr to fix

                  Method addSharedOptions has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function addSharedOptions( $maintenance ) {
                          $maintenance->addOption( 'startOver', 'Blow away the identified index and rebuild it with ' .
                              'no data.' );
                          $maintenance->addOption( 'indexIdentifier', "Set the identifier of the index to work on.  " .
                              "You'll need this if you have an index in production serving queries and you have " .
                  Severity: Minor
                  Found in maintenance/UpdateOneSearchIndexConfig.php - About 1 hr to fix

                    Method createIndex has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function createIndex() {
                            // This is "create only" for now.
                            if ( $this->getIndex()->exists() ) {
                                throw new RuntimeException( "Index already exists." );
                            }
                    Severity: Minor
                    Found in maintenance/UpdateSuggesterIndex.php - About 1 hr to fix

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                                  foreach ( $feature->getValueDelimiters() as $delimConfig ) {
                                      Assert::precondition( strlen( $delimConfig['delimiter'] ) === 1,
                                          "Value delimiter must be a single byte char" );
                                      $delim = preg_quote( $delimConfig['delimiter'], '/' );
                                      $allDelims .= $delim;
                      Severity: Major
                      Found in includes/Parser/QueryStringRegex/KeywordParser.php and 1 other location - About 1 hr to fix
                      includes/Query/SimpleKeywordFeature.php on lines 157..167

                      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 107.

                      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

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                                  foreach ( $this->getValueDelimiters() as $delimConfig ) {
                                      Assert::precondition( strlen( $delimConfig['delimiter'] ) === 1,
                                          "Value delimiter must be a single byte char" );
                                      $delim = preg_quote( $delimConfig['delimiter'], '/' );
                                      $allDelims .= $delim;
                      Severity: Major
                      Found in includes/Query/SimpleKeywordFeature.php and 1 other location - About 1 hr to fix
                      includes/Parser/QueryStringRegex/KeywordParser.php on lines 145..155

                      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 107.

                      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

                      Further Reading

                      Method reportUpdateMetrics has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function reportUpdateMetrics(
                              \Elastica\Bulk\ResponseSet $responseSet, $indexSuffix, $sent
                          ) {
                              $updateStats = [
                                  'sent' => $sent,
                      Severity: Minor
                      Found in includes/DataSender.php - About 1 hr to fix

                        Method determineCirrusDocId has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private function determineCirrusDocId( PageIdentity $title ) {
                                $hasRedirects = false;
                                $seen = [];
                                $now = wfTimestamp( TS_MW );
                                $services = MediaWikiServices::getInstance();
                        Severity: Minor
                        Found in includes/Api/ApiTrait.php - About 1 hr to fix

                          Method fixupWholeQueryString has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function fixupWholeQueryString( $string ) {
                                  $escapeBadSyntax = static function ( $matches ) {
                                      return preg_replace( '/(?=[^\s\w])/', '\\', $matches[0] );
                                  };
                          
                          
                          Severity: Minor
                          Found in includes/Search/Escaper.php - About 1 hr to fix

                            Method __construct has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function __construct(
                                    $langCode,
                                    array $plugins,
                                    SearchConfig $config = null,
                                    CirrusSearchHookRunner $cirrusSearchHookRunner = null
                            Severity: Minor
                            Found in includes/Maintenance/AnalysisConfigBuilder.php - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language