wikimedia/mediawiki-extensions-Translate

View on GitHub
src/MessageGroupProcessing/MessageGroups.php

Summary

Maintainability
F
3 days
Test Coverage

File MessageGroups.php has 413 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
declare( strict_types = 1 );

namespace MediaWiki\Extension\Translate\MessageGroupProcessing;

Severity: Minor
Found in src/MessageGroupProcessing/MessageGroups.php - About 5 hrs to fix

    MessageGroups has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MessageGroups {
        /** @var MessageGroup[]|null Map of (group ID => MessageGroup) */
        private $groups;
        /** @var MessageGroupLoader[]|null */
        private $groupLoaders;
    Severity: Minor
    Found in src/MessageGroupProcessing/MessageGroups.php - About 3 hrs to fix

      Function getParentGroups has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function getParentGroups( MessageGroup $targetGroup ): array {
              $ids = self::getSharedGroups( $targetGroup );
              if ( $ids === [] ) {
                  return [];
              }
      Severity: Minor
      Found in src/MessageGroupProcessing/MessageGroups.php - About 3 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

      Function getGroupStructure has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function getGroupStructure(): array {
              $groups = self::getAllGroups();
      
              // Determine the top level groups of the tree
              $tree = $groups;
      Severity: Minor
      Found in src/MessageGroupProcessing/MessageGroups.php - About 2 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 getParentGroups has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function getParentGroups( MessageGroup $targetGroup ): array {
              $ids = self::getSharedGroups( $targetGroup );
              if ( $ids === [] ) {
                  return [];
              }
      Severity: Minor
      Found in src/MessageGroupProcessing/MessageGroups.php - About 1 hr to fix

        Method getGroupStructure has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function getGroupStructure(): array {
                $groups = self::getAllGroups();
        
                // Determine the top level groups of the tree
                $tree = $groups;
        Severity: Minor
        Found in src/MessageGroupProcessing/MessageGroups.php - About 1 hr to fix

          Method getGroupLoaders has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function getGroupLoaders(): array {
                  if ( $this->groupLoaders !== null ) {
                      return $this->groupLoaders;
                  }
          
          
          Severity: Minor
          Found in src/MessageGroupProcessing/MessageGroups.php - About 1 hr to fix

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

                public static function isTranslatableMessage( MessageHandle $handle, string $targetLanguage ): bool {
                    static $cache = [];
            
                    if ( !$handle->isValid() ) {
                        return false;
            Severity: Minor
            Found in src/MessageGroupProcessing/MessageGroups.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 subGroups has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function subGroups(
                    AggregateMessageGroup $parent,
                    array &$childIds = [],
                    string $fname = 'caller'
                ): array {
            Severity: Minor
            Found in src/MessageGroupProcessing/MessageGroups.php - About 1 hr to fix

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

                  public static function getGroupsById( array $ids, bool $skipMeta = false ): array {
                      $groups = [];
                      foreach ( $ids as $id ) {
                          $group = self::getGroup( $id );
              
              
              Severity: Minor
              Found in src/MessageGroupProcessing/MessageGroups.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 expandWildcards has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function expandWildcards( $ids ): array {
                      $all = [];
              
                      $ids = (array)$ids;
                      foreach ( $ids as $index => $id ) {
              Severity: Minor
              Found in src/MessageGroupProcessing/MessageGroups.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 isTranslatableMessage has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function isTranslatableMessage( MessageHandle $handle, string $targetLanguage ): bool {
                      static $cache = [];
              
                      if ( !$handle->isValid() ) {
                          return false;
              Severity: Minor
              Found in src/MessageGroupProcessing/MessageGroups.php - About 1 hr to fix

                Function labelExists has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function labelExists( string $name ): bool {
                        $groups = self::getAllGroups();
                        foreach ( $groups as $group ) {
                            if ( $group instanceof AggregateMessageGroup ) {
                                if ( $group->getLabel() === $name ) {
                Severity: Minor
                Found in src/MessageGroupProcessing/MessageGroups.php - About 25 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