wikimedia/mediawiki-extensions-Wikibase

View on GitHub
repo/includes/Parsers/DateFormatParser.php

Summary

Maintainability
D
2 days
Test Coverage

Method parseDateFormat has 120 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function parseDateFormat( $format ) {
        $length = strlen( $format );

        $number = $this->getNumberPattern();
        $notFollowedByNumber = '(?!' . $number . ')';
Severity: Major
Found in repo/includes/Parsers/DateFormatParser.php - About 4 hrs to fix

    Function parseDateFormat has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        private function parseDateFormat( $format ) {
            $length = strlen( $format );
    
            $number = $this->getNumberPattern();
            $notFollowedByNumber = '(?!' . $number . ')';
    Severity: Minor
    Found in repo/includes/Parsers/DateFormatParser.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 stringParse has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function stringParse( $value ) {
            $date = $this->parseDate( $value );
            $precision = TimeValue::PRECISION_YEAR;
            $time = [ $this->parseFormattedNumber( $date['year'] ), 0, 0, 0, 0, 0 ];
    
    
    Severity: Minor
    Found in repo/includes/Parsers/DateFormatParser.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

    File DateFormatParser.php has 259 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace Wikibase\Repo\Parsers;
    
    use DataValues\IllegalValueException;
    Severity: Minor
    Found in repo/includes/Parsers/DateFormatParser.php - About 2 hrs to fix

      Consider simplifying this complex logical expression.
      Open

              if ( !isset( $matches['year'] )
                  || ( isset( $matches['day'] ) && !isset( $matches['month'] ) )
                  || ( isset( $matches['hour'] ) && !isset( $matches['day'] ) )
                  || ( isset( $matches['minute'] ) && !isset( $matches['hour'] ) )
                  || ( isset( $matches['second'] ) && !isset( $matches['minute'] ) )
      Severity: Critical
      Found in repo/includes/Parsers/DateFormatParser.php - About 1 hr to fix

        Method stringParse has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function stringParse( $value ) {
                $date = $this->parseDate( $value );
                $precision = TimeValue::PRECISION_YEAR;
                $time = [ $this->parseFormattedNumber( $date['year'] ), 0, 0, 0, 0, 0 ];
        
        
        Severity: Minor
        Found in repo/includes/Parsers/DateFormatParser.php - About 1 hr to fix

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

              private function parseDate( $input ) {
                  $pattern = $this->parseDateFormat( $this->getDateFormat() );
          
                  AtEase::suppressWarnings();
                  $success = preg_match( $pattern, $input, $matches );
          Severity: Minor
          Found in repo/includes/Parsers/DateFormatParser.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

          Avoid deeply nested control flow statements.
          Open

                                  if ( isset( $date['second'] ) ) {
                                      $precision = TimeValue::PRECISION_SECOND;
                                      $time[5] = $this->parseFormattedNumber( $date['second'] );
                                  }
          Severity: Major
          Found in repo/includes/Parsers/DateFormatParser.php - About 45 mins to fix

            There are no issues that match your filters.

            Category
            Status