wikimedia/mediawiki-core

View on GitHub
includes/user/UserNameUtils.php

Summary

Maintainability
C
7 hrs
Test Coverage

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

    public function getCanonical( string $name, string $validate = self::RIGOR_VALID ) {
        // Force usernames to capital
        $name = $this->contentLang->ucfirst( $name );

        // Reject names containing '#'; these will be cleaned up
Severity: Minor
Found in includes/user/UserNameUtils.php - About 1 hr to fix

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

        public function isValid( string $name ): bool {
            if ( $name === ''
                || $this->isIP( $name )
                || $this->isValidIPRange( $name )
                || $this->isLikeIPv4DashRange( $name )
    Severity: Minor
    Found in includes/user/UserNameUtils.php - About 1 hr to fix

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

          public function isUsable( string $name ): bool {
              // Must be a valid username, obviously ;)
              if ( !$this->isValid( $name ) ) {
                  return false;
              }
      Severity: Minor
      Found in includes/user/UserNameUtils.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

      Consider simplifying this complex logical expression.
      Open

              if ( $name === ''
                  || $this->isIP( $name )
                  || $this->isValidIPRange( $name )
                  || $this->isLikeIPv4DashRange( $name )
                  || str_contains( $name, '/' )
      Severity: Major
      Found in includes/user/UserNameUtils.php - About 1 hr to fix

        Method __construct has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                ServiceOptions $options,
                Language $contentLang,
                LoggerInterface $logger,
                TitleParser $titleParser,
                ITextFormatter $textFormatter,
        Severity: Major
        Found in includes/user/UserNameUtils.php - About 50 mins to fix

          Function getCanonical has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getCanonical( string $name, string $validate = self::RIGOR_VALID ) {
                  // Force usernames to capital
                  $name = $this->contentLang->ucfirst( $name );
          
                  // Reject names containing '#'; these will be cleaned up
          Severity: Minor
          Found in includes/user/UserNameUtils.php - About 45 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

          Avoid too many return statements within this method.
          Open

                          return $this->isUsable( $name ) ? $name : false;
          Severity: Major
          Found in includes/user/UserNameUtils.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                            return $this->isCreatable( $name ) ? $name : false;
            Severity: Major
            Found in includes/user/UserNameUtils.php - About 30 mins to fix

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

                  public function isValid( string $name ): bool {
                      if ( $name === ''
                          || $this->isIP( $name )
                          || $this->isValidIPRange( $name )
                          || $this->isLikeIPv4DashRange( $name )
              Severity: Minor
              Found in includes/user/UserNameUtils.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