wikimedia/mediawiki-extensions-Translate

View on GitHub
src/MessageLoading/MessageCollection.php

Summary

Maintainability
F
3 days
Test Coverage

File MessageCollection.php has 546 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
declare( strict_types = 1 );

namespace MediaWiki\Extension\Translate\MessageLoading;

Severity: Major
Found in src/MessageLoading/MessageCollection.php - About 1 day to fix

    MessageCollection has 44 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MessageCollection implements ArrayAccess, Iterator, Countable {
        /**
         * The queries can get very large because each message title is specified
         * individually. Very large queries can confuse the database query planner.
         * Queries are split into multiple separate queries having at most this many
    Severity: Minor
    Found in src/MessageLoading/MessageCollection.php - About 6 hrs to fix

      Function initMessages has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
      Open

          public function initMessages(): void {
              if ( $this->messages !== null ) {
                  return;
              }
      
      
      Severity: Minor
      Found in src/MessageLoading/MessageCollection.php - About 5 hrs 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 initMessages has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function initMessages(): void {
              if ( $this->messages !== null ) {
                  return;
              }
      
      
      Severity: Major
      Found in src/MessageLoading/MessageCollection.php - About 2 hrs to fix

        Function filterChanged has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            private function filterChanged( array $keys, bool $condition ): array {
                $this->loadData( $keys );
        
                $origKeys = [];
                if ( !$condition ) {
        Severity: Minor
        Found in src/MessageLoading/MessageCollection.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 applyFilter has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            private function applyFilter( string $filter, bool $condition, ?int $value ): void {
                $keys = $this->keys;
                if ( $filter === 'fuzzy' ) {
                    $keys = $this->filterFuzzy( $keys, $condition );
                } elseif ( $filter === 'hastranslation' ) {
        Severity: Minor
        Found in src/MessageLoading/MessageCollection.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 filterChanged has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function filterChanged( array $keys, bool $condition ): array {
                $this->loadData( $keys );
        
                $origKeys = [];
                if ( !$condition ) {
        Severity: Minor
        Found in src/MessageLoading/MessageCollection.php - About 1 hr to fix

          Method applyFilter has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function applyFilter( string $filter, bool $condition, ?int $value ): void {
                  $keys = $this->keys;
                  if ( $filter === 'fuzzy' ) {
                      $keys = $this->filterFuzzy( $keys, $condition );
                  } elseif ( $filter === 'hastranslation' ) {
          Severity: Minor
          Found in src/MessageLoading/MessageCollection.php - About 1 hr to fix

            Function getAuthors has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                public function getAuthors(): array {
                    $this->loadTranslations();
            
                    $authors = array_flip( $this->authors );
            
            
            Severity: Minor
            Found in src/MessageLoading/MessageCollection.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 filterOnCondition has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                private function filterOnCondition( array $keys, array $condKeys, bool $condition = true ): array {
                    if ( $condition ) {
                        // Delete $condKeys from $keys
                        foreach ( array_keys( $condKeys ) as $key ) {
                            unset( $keys[$key] );
            Severity: Minor
            Found in src/MessageLoading/MessageCollection.php - About 55 mins 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

            There are no issues that match your filters.

            Category
            Status