Firesphere/silverstripe-csp-headers

View on GitHub

Showing 10 of 145 total issues

Function toYml has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    public static function toYml($response, $return = false)
    {
        $cspHeader = $response->getHeader('content-security-policy') ?? $response->getHeader('content-security-policy-report-only');

        $asArray = explode(';', $cspHeader);
Severity: Minor
Found in src/Helpers/CSPConvertor.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 onBeforeInit has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    public function onBeforeInit()
    {
        if (self::$isTesting || !DB::is_active() || !ClassInfo::hasTable('Member') || Director::is_cli()) {
            return;
        }
Severity: Minor
Found in src/Extensions/ControllerCSPExtension.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

File ControllerCSPExtension.php has 273 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php


namespace Firesphere\CSPHeaders\Extensions;

Severity: Minor
Found in src/Extensions/ControllerCSPExtension.php - About 2 hrs to fix

    Method addPermissionsHeaders has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function addPermissionsHeaders(mixed $ymlConfig, Controller $controller)
        {
            $config = Injector::inst()->convertServiceProperty($ymlConfig);
            $policies = [];
            foreach ($config as $key => $value) {
    Severity: Major
    Found in src/Extensions/ControllerCSPExtension.php - About 2 hrs to fix

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

          public static function toYml($response, $return = false)
          {
              $cspHeader = $response->getHeader('content-security-policy') ?? $response->getHeader('content-security-policy-report-only');
      
              $asArray = explode(';', $cspHeader);
      Severity: Major
      Found in src/Helpers/CSPConvertor.php - About 2 hrs to fix

        Method onBeforeInit has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function onBeforeInit()
            {
                if (self::$isTesting || !DB::is_active() || !ClassInfo::hasTable('Member') || Director::is_cli()) {
                    return;
                }
        Severity: Major
        Found in src/Extensions/ControllerCSPExtension.php - About 2 hrs to fix

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

              private function addPermissionsHeaders(mixed $ymlConfig, Controller $controller)
              {
                  $config = Injector::inst()->convertServiceProperty($ymlConfig);
                  $policies = [];
                  foreach ($config as $key => $value) {
          Severity: Minor
          Found in src/Extensions/ControllerCSPExtension.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 onBeforeWrite has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public function onBeforeWrite()
              {
                  $body = null;
                  // Since this is called from CSP Backend, an SRI for external files is automatically created
                  if (!Director::is_site_url($this->File)) {
          Severity: Minor
          Found in src/Models/SRI.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 addCSPHeaders has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              private function addCSPHeaders(mixed $ymlConfig, Controller $owner): void
              {
                  $config = Injector::inst()->convertServiceProperty($ymlConfig);
                  $legacy = $config['legacy'] ?? true;
                  $unsafeCSSInline = $config['style-src']['unsafe-inline'];
          Severity: Minor
          Found in src/Extensions/ControllerCSPExtension.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 buildSRI has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function buildSRI($file, array $htmlAttributes): array
              {
                  $skipFiles = $this->config()->get('skip_domains') ?? [];
                  foreach ($skipFiles as $filename) {
                      if (strpos($file, $filename) === 0) {
          Severity: Minor
          Found in src/Builders/SRIBuilder.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

          Severity
          Category
          Status
          Source
          Language