wikimedia/mediawiki-core

View on GitHub
includes/Request/ContentSecurityPolicy.php

Summary

Maintainability
D
2 days
Test Coverage

Function makeCSPDirectives has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

    private function makeCSPDirectives( $policyConfig, $mode ) {
        if ( $policyConfig === false ) {
            // CSP is disabled
            return '';
        }
Severity: Minor
Found in includes/Request/ContentSecurityPolicy.php - About 6 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 makeCSPDirectives has 110 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function makeCSPDirectives( $policyConfig, $mode ) {
        if ( $policyConfig === false ) {
            // CSP is disabled
            return '';
        }
Severity: Major
Found in includes/Request/ContentSecurityPolicy.php - About 4 hrs to fix

    File ContentSecurityPolicy.php has 320 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/Request/ContentSecurityPolicy.php - About 3 hrs to fix

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

          private function getAdditionalSelfUrls() {
              // XXX on a foreign repo, the included description page can have anything on it,
              // including inline scripts. But nobody does that.
      
              // In principle, you can have even more complex configs... (e.g. The urlsByExt option)
      Severity: Minor
      Found in includes/Request/ContentSecurityPolicy.php - About 1 hr to fix

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

            private function getAdditionalSelfUrls() {
                // XXX on a foreign repo, the included description page can have anything on it,
                // including inline scripts. But nobody does that.
        
                // In principle, you can have even more complex configs... (e.g. The urlsByExt option)
        Severity: Minor
        Found in includes/Request/ContentSecurityPolicy.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 getAdditionalSelfUrlsScript has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            private function getAdditionalSelfUrlsScript() {
                $additionalUrls = [];
                // wgExtensionAssetsPath for ?debug=true mode
                $pathVars = [
                    MainConfigNames::LoadScript,
        Severity: Minor
        Found in includes/Request/ContentSecurityPolicy.php - About 55 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 prepareUrlForCSP has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            private function prepareUrlForCSP( $url ) {
                $result = false;
                if ( preg_match( '/^[a-z][a-z0-9+.-]*:$/i', $url ) ) {
                    // A schema source (e.g. blob: or data:)
                    return $url;
        Severity: Minor
        Found in includes/Request/ContentSecurityPolicy.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

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

            private function getCORSSources() {
                $additionalUrls = [];
                $CORSSources = $this->mwConfig->get( MainConfigNames::CrossSiteAJAXdomains );
                foreach ( $CORSSources as $source ) {
                    if ( strpos( $source, '?' ) !== false ) {
        Severity: Minor
        Found in includes/Request/ContentSecurityPolicy.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