wikimedia/mediawiki-extensions-Translate

View on GitHub
src/FileFormatSupport/GettextFormat.php

Summary

Maintainability
F
4 days
Test Coverage

File GettextFormat.php has 512 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
declare( strict_types = 1 );

namespace MediaWiki\Extension\Translate\FileFormatSupport;

Severity: Major
Found in src/FileFormatSupport/GettextFormat.php - About 1 day to fix

    Function parseGettextSection has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        private function parseGettextSection( string $section, ?int $pluralCount ): ?array {
            if ( trim( $section ) === '' ) {
                return null;
            }
    
    
    Severity: Minor
    Found in src/FileFormatSupport/GettextFormat.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

    GettextFormat has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class GettextFormat extends SimpleFormat implements MetaYamlSchemaExtender {
        private bool $allowPotMode = false;
        private bool $offlineMode = false;
    
        public function supportsFuzzy(): string {
    Severity: Minor
    Found in src/FileFormatSupport/GettextFormat.php - About 3 hrs to fix

      Function parseGettext has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          private function parseGettext( string $data ): array {
              $mangler = $this->group->getMangler();
              $useCtxtAsKey = $this->extra['CtxtAsKey'] ?? false;
              $keyAlgorithm = 'simple';
              if ( isset( $this->extra['keyAlgorithm'] ) ) {
      Severity: Minor
      Found in src/FileFormatSupport/GettextFormat.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 parseGettext has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function parseGettext( string $data ): array {
              $mangler = $this->group->getMangler();
              $useCtxtAsKey = $this->extra['CtxtAsKey'] ?? false;
              $keyAlgorithm = 'simple';
              if ( isset( $this->extra['keyAlgorithm'] ) ) {
      Severity: Major
      Found in src/FileFormatSupport/GettextFormat.php - About 2 hrs to fix

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

            private function formatMessageBlock(
                string $key,
                Message $message,
                array $trans,
                array $pot,
        Severity: Minor
        Found in src/FileFormatSupport/GettextFormat.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 parseGettextSection has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function parseGettextSection( string $section, ?int $pluralCount ): ?array {
                if ( trim( $section ) === '' ) {
                    return null;
                }
        
        
        Severity: Major
        Found in src/FileFormatSupport/GettextFormat.php - About 2 hrs to fix

          Method doGettextHeader has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function doGettextHeader( MessageCollection $collection, array $template ): string {
                  global $wgSitename;
          
                  $code = $collection->code;
                  $name = Utilities::getLanguageName( $code );
          Severity: Major
          Found in src/FileFormatSupport/GettextFormat.php - About 2 hrs to fix

            Method formatMessageBlock has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function formatMessageBlock(
                    string $key,
                    Message $message,
                    array $trans,
                    array $pot,
            Severity: Minor
            Found in src/FileFormatSupport/GettextFormat.php - About 2 hrs to fix

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

                  protected function writeReal( MessageCollection $collection ): string {
                      // FIXME: this should be the source language
                      $pot = $this->read( 'en' ) ?? [];
                      $code = $collection->code;
                      $template = $this->read( $code ) ?? [];
              Severity: Minor
              Found in src/FileFormatSupport/GettextFormat.php - About 1 hr to fix

                Method formatMessageBlock has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        string $key,
                        Message $message,
                        array $trans,
                        array $pot,
                        int $pluralCount,
                Severity: Minor
                Found in src/FileFormatSupport/GettextFormat.php - About 45 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return false;
                  Severity: Major
                  Found in src/FileFormatSupport/GettextFormat.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return GettextPlural::unflatten( $a, $expectedPluralCount )
                                === GettextPlural::unflatten( $b, $expectedPluralCount );
                    Severity: Major
                    Found in src/FileFormatSupport/GettextFormat.php - About 30 mins to fix

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

                          private function processGettextPluralMessage( ?int $pluralCount, string $section ): string {
                              $actualForms = [];
                      
                              for ( $i = 0; $i < $pluralCount; $i++ ) {
                                  $match = $this->expectKeyword( "msgstr\\[$i\\]", $section );
                      Severity: Minor
                      Found in src/FileFormatSupport/GettextFormat.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

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

                          private function doGettextHeader( MessageCollection $collection, array $template ): string {
                              global $wgSitename;
                      
                              $code = $collection->code;
                              $name = Utilities::getLanguageName( $code );
                      Severity: Minor
                      Found in src/FileFormatSupport/GettextFormat.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

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

                          public function isContentEqual( ?string $a, ?string $b ): bool {
                              if ( $a === $b ) {
                                  return true;
                              }
                      
                      
                      Severity: Minor
                      Found in src/FileFormatSupport/GettextFormat.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