wikimedia/mediawiki-core

View on GitHub
includes/HookContainer/HookContainer.php

Summary

Maintainability
D
2 days
Test Coverage

File HookContainer.php has 374 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Minor
Found in includes/HookContainer/HookContainer.php - About 5 hrs to fix

    Function normalizeHandler has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        private function normalizeHandler( string $hook, $handler, array $options = [] ) {
            if ( is_object( $handler ) && !$handler instanceof Closure ) {
                $handler = [ $handler, $this->getHookMethodName( $hook ) ];
            }
    
    
    Severity: Minor
    Found in includes/HookContainer/HookContainer.php - About 4 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 normalizeHandler has 88 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function normalizeHandler( string $hook, $handler, array $options = [] ) {
            if ( is_object( $handler ) && !$handler instanceof Closure ) {
                $handler = [ $handler, $this->getHookMethodName( $hook ) ];
            }
    
    
    Severity: Major
    Found in includes/HookContainer/HookContainer.php - About 3 hrs to fix

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

          public function emitDeprecationWarnings() {
              $deprecatedHooks = $this->registry->getDeprecatedHooks();
              $extensionHooks = $this->registry->getExtensionHooks();
      
              foreach ( $extensionHooks as $name => $handlers ) {
      Severity: Minor
      Found in includes/HookContainer/HookContainer.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 run has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function run( string $hook, array $args = [], array $options = [] ): bool {
              $checkDeprecation = isset( $options['deprecatedVersion'] );
      
              $abortable = $options['abortable'] ?? true;
              foreach ( $this->getHandlers( $hook, $options ) as $handler ) {
      Severity: Minor
      Found in includes/HookContainer/HookContainer.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 run has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function run( string $hook, array $args = [], array $options = [] ): bool {
              $checkDeprecation = isset( $options['deprecatedVersion'] );
      
              $abortable = $options['abortable'] ?? true;
              foreach ( $this->getHandlers( $hook, $options ) as $handler ) {
      Severity: Minor
      Found in includes/HookContainer/HookContainer.php - About 1 hr to fix

        Function describeHandler has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private function describeHandler( string $hook, $handler ): ?string {
                if ( is_array( $handler ) ) {
                    // already normalized
                    if ( isset( $handler['functionName'] ) ) {
                        return $handler['functionName'];
        Severity: Minor
        Found in includes/HookContainer/HookContainer.php - About 35 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 getHandlers has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private function getHandlers( string $hook, array $options = [] ): array {
                if ( !isset( $this->handlers[$hook] ) ) {
                    $handlers = [];
                    $registeredHooks = $this->registry->getExtensionHooks();
                    $configuredHooks = $this->registry->getGlobalHooks();
        Severity: Minor
        Found in includes/HookContainer/HookContainer.php - About 35 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 false;
        Severity: Major
        Found in includes/HookContainer/HookContainer.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return false;
          Severity: Major
          Found in includes/HookContainer/HookContainer.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return [
                        'callback' => $callback,
                        'functionName' => self::callableToString( $callback ),
                        'args' => $handler,
                    ];
            Severity: Major
            Found in includes/HookContainer/HookContainer.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return [
                              'callback' => $callback,
                              'functionName' => self::callableToString( $callback ),
                          ];
              Severity: Major
              Found in includes/HookContainer/HookContainer.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                    return false;
                Severity: Major
                Found in includes/HookContainer/HookContainer.php - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status