yiisoft/yii-web

View on GitHub

Showing 29 of 29 total issues

Function process has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $actualHost = $request->getServerParams()['REMOTE_ADDR'] ?? null;
        if ($actualHost === null) {
            // Validation is not possible.
Severity: Minor
Found in src/Middleware/TrustedHostsNetworkResolver.php - About 1 day 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 TrustedHostsNetworkResolver.php has 365 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Web\Middleware;
Severity: Minor
Found in src/Middleware/TrustedHostsNetworkResolver.php - About 4 hrs to fix

    Method process has 107 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
        {
            $actualHost = $request->getServerParams()['REMOTE_ADDR'] ?? null;
            if ($actualHost === null) {
                // Validation is not possible.
    Severity: Major
    Found in src/Middleware/TrustedHostsNetworkResolver.php - About 4 hrs to fix

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

          public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
          {
              $newScheme = null;
              foreach ($this->protocolHeaders as $header => $data) {
                  if (!$request->hasHeader($header)) {
      Severity: Minor
      Found in src/Middleware/BasicNetworkResolver.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 getElementsByRfc7239 has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          private function getElementsByRfc7239(array $forwards): array
          {
              $list = [];
              foreach ($forwards as $forward) {
                  $data = HeaderValueHelper::getParameters($forward);
      Severity: Minor
      Found in src/Middleware/TrustedHostsNetworkResolver.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 process has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
          {
              $uri = $request->getUri();
              $path = $uri->getPath();
              $prefix = $this->prefix;
      Severity: Minor
      Found in src/Middleware/SubFolder.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 withAddedTrustedHosts has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function withAddedTrustedHosts(
              array $hosts,
              // Defining default headers is not secure!
              array $ipHeaders = [],
              array $protocolHeaders = [],
      Severity: Minor
      Found in src/Middleware/TrustedHostsNetworkResolver.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

      Function prepareProtocolHeaders has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          private function prepareProtocolHeaders(array $protocolHeaders): array
          {
              $output = [];
              foreach ($protocolHeaders as $header => $protocolAndAcceptedValues) {
                  $header = strtolower($header);
      Severity: Minor
      Found in src/Middleware/TrustedHostsNetworkResolver.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

      Method withAddedTrustedHosts has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function withAddedTrustedHosts(
              array $hosts,
              // Defining default headers is not secure!
              array $ipHeaders = [],
              array $protocolHeaders = [],
      Severity: Minor
      Found in src/Middleware/TrustedHostsNetworkResolver.php - About 1 hr to fix

        Function getHeadersFromGlobals has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            private function getHeadersFromGlobals(): array
            {
                if (function_exists('getallheaders')) {
                    $headers = getallheaders();
                    return $headers === false ? [] : $headers;
        Severity: Minor
        Found in src/ServerRequestFactory.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 process has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
            {
                $uri = $request->getUri();
                $path = $uri->getPath();
                $prefix = $this->prefix;
        Severity: Minor
        Found in src/Middleware/SubFolder.php - About 1 hr to fix

          Function process has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
              {
                  if (
                      ($this->lastModified === null && $this->etagSeed === null) ||
                      !\in_array($request->getMethod(), [Method::GET, Method::HEAD], true)
          Severity: Minor
          Found in src/Middleware/HttpCache.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 emit has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public function emit(ResponseInterface $response, bool $withoutBody = false): void
              {
                  $status = $response->getStatusCode();
                  $withoutBody = $withoutBody || !$this->shouldOutputBody($response);
                  $withoutContentLength = $withoutBody || $response->hasHeader('Transfer-Encoding');
          Severity: Minor
          Found in src/SapiEmitter.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 createFromParameters has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              public function createFromParameters(array $server, array $headers = [], array $cookies = [], array $get = [], array $post = [], array $files = [], $body = null): ServerRequestInterface
              {
                  $method = $server['REQUEST_METHOD'] ?? null;
                  if ($method === null) {
                      throw new RuntimeException('Unable to determine HTTP request method.');
          Severity: Minor
          Found in src/ServerRequestFactory.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 process has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
              {
                  if (
                      ($this->lastModified === null && $this->etagSeed === null) ||
                      !\in_array($request->getMethod(), [Method::GET, Method::HEAD], true)
          Severity: Minor
          Found in src/Middleware/HttpCache.php - About 1 hr to fix

            Method getElementsByRfc7239 has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function getElementsByRfc7239(array $forwards): array
                {
                    $list = [];
                    foreach ($forwards as $forward) {
                        $data = HeaderValueHelper::getParameters($forward);
            Severity: Minor
            Found in src/Middleware/TrustedHostsNetworkResolver.php - About 1 hr to fix

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

                  public function createFromParameters(array $server, array $headers = [], array $cookies = [], array $get = [], array $post = [], array $files = [], $body = null): ServerRequestInterface
                  {
                      $method = $server['REQUEST_METHOD'] ?? null;
                      if ($method === null) {
                          throw new RuntimeException('Unable to determine HTTP request method.');
              Severity: Minor
              Found in src/ServerRequestFactory.php - About 1 hr to fix

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

                    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
                    {
                        $newScheme = null;
                        foreach ($this->protocolHeaders as $header => $data) {
                            if (!$request->hasHeader($header)) {
                Severity: Minor
                Found in src/Middleware/BasicNetworkResolver.php - About 1 hr to fix

                  Method emit has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function emit(ResponseInterface $response, bool $withoutBody = false): void
                      {
                          $status = $response->getStatusCode();
                          $withoutBody = $withoutBody || !$this->shouldOutputBody($response);
                          $withoutContentLength = $withoutBody || $response->hasHeader('Transfer-Encoding');
                  Severity: Minor
                  Found in src/SapiEmitter.php - About 1 hr to fix

                    Function getUri has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function getUri(array $server): UriInterface
                        {
                            $uri = $this->uriFactory->createUri();
                    
                            if (array_key_exists('HTTPS', $server) && $server['HTTPS'] !== '' && $server['HTTPS'] !== 'off') {
                    Severity: Minor
                    Found in src/ServerRequestFactory.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

                    Severity
                    Category
                    Status
                    Source
                    Language