laravel/framework

View on GitHub
src/Illuminate/Testing/TestResponse.php

Summary

Maintainability
F
1 wk
Test Coverage

File TestResponse.php has 944 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Illuminate\Testing;

use ArrayAccess;
Severity: Major
Found in src/Illuminate/Testing/TestResponse.php - About 2 days to fix

    TestResponse has 85 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class TestResponse implements ArrayAccess
    {
        use Concerns\AssertsStatusCodes, Conditionable, Dumpable, Tappable, Macroable {
            __call as macroCall;
        }
    Severity: Major
    Found in src/Illuminate/Testing/TestResponse.php - About 1 day to fix

      Function assertInvalid has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          public function assertInvalid($errors = null,
                                        $errorBag = 'default',
                                        $responseKey = 'errors')
          {
              if ($this->baseResponse->headers->get('Content-Type') === 'application/json') {
      Severity: Minor
      Found in src/Illuminate/Testing/TestResponse.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 assertJsonValidationErrors has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          public function assertJsonValidationErrors($errors, $responseKey = 'errors')
          {
              $errors = Arr::wrap($errors);
      
              PHPUnit::assertNotEmpty($errors, 'No validation errors were provided.');
      Severity: Minor
      Found in src/Illuminate/Testing/TestResponse.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 assertInvalid has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function assertInvalid($errors = null,
                                        $errorBag = 'default',
                                        $responseKey = 'errors')
          {
              if ($this->baseResponse->headers->get('Content-Type') === 'application/json') {
      Severity: Minor
      Found in src/Illuminate/Testing/TestResponse.php - About 1 hr to fix

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

            public function assertDownload($filename = null)
            {
                $contentDisposition = explode(';', $this->headers->get('content-disposition'));
        
                if (trim($contentDisposition[0]) !== 'attachment') {
        Severity: Minor
        Found in src/Illuminate/Testing/TestResponse.php - About 1 hr to fix

          Method assertJsonValidationErrors has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function assertJsonValidationErrors($errors, $responseKey = 'errors')
              {
                  $errors = Arr::wrap($errors);
          
                  PHPUnit::assertNotEmpty($errors, 'No validation errors were provided.');
          Severity: Minor
          Found in src/Illuminate/Testing/TestResponse.php - About 1 hr to fix

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

                public function assertSessionHasInput($key, $value = null)
                {
                    if (is_array($key)) {
                        foreach ($key as $k => $v) {
                            if (is_int($k)) {
            Severity: Minor
            Found in src/Illuminate/Testing/TestResponse.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 assertDownload has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                public function assertDownload($filename = null)
                {
                    $contentDisposition = explode(';', $this->headers->get('content-disposition'));
            
                    if (trim($contentDisposition[0]) !== 'attachment') {
            Severity: Minor
            Found in src/Illuminate/Testing/TestResponse.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 transformNotSuccessfulException has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                public function transformNotSuccessfulException($exception)
                {
                    if (! $exception instanceof ExpectationFailedException) {
                        return $exception;
                    }
            Severity: Minor
            Found in src/Illuminate/Testing/TestResponse.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 assertValid has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function assertValid($keys = null, $errorBag = 'default', $responseKey = 'errors')
                {
                    if ($this->baseResponse->headers->get('Content-Type') === 'application/json') {
                        return $this->assertJsonMissingValidationErrors($keys, $responseKey);
                    }
            Severity: Minor
            Found in src/Illuminate/Testing/TestResponse.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 $exception;
            Severity: Major
            Found in src/Illuminate/Testing/TestResponse.php - About 30 mins to fix

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

                  public function getCookie($cookieName, $decrypt = true, $unserialize = false)
                  {
                      foreach ($this->headers->getCookies() as $cookie) {
                          if ($cookie->getName() === $cookieName) {
                              if (! $decrypt) {
              Severity: Minor
              Found in src/Illuminate/Testing/TestResponse.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

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

                  public function assertViewHas($key, $value = null)
                  {
                      if (is_array($key)) {
                          return $this->assertViewHasAll($key);
                      }
              Severity: Minor
              Found in src/Illuminate/Testing/TestResponse.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

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

                  public function assertSessionDoesntHaveErrors($keys = [], $format = null, $errorBag = 'default')
                  {
                      $keys = (array) $keys;
              
                      if (empty($keys)) {
              Severity: Minor
              Found in src/Illuminate/Testing/TestResponse.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

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      if (is_null($value)) {
                          PHPUnit::assertTrue(Arr::has($this->original->gatherData(), $key));
                      } elseif ($value instanceof Closure) {
                          PHPUnit::assertTrue($value(Arr::get($this->original->gatherData(), $key)));
                      } elseif ($value instanceof Model) {
              Severity: Major
              Found in src/Illuminate/Testing/TestResponse.php and 1 other location - About 1 day to fix
              src/Illuminate/Testing/TestView.php on lines 58..73

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 248.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      if (is_null($value)) {
                          PHPUnit::assertTrue(
                              $this->session()->hasOldInput($key),
                              "Session is missing expected key [{$key}]."
                          );
              Severity: Minor
              Found in src/Illuminate/Testing/TestResponse.php and 1 other location - About 50 mins to fix
              src/Illuminate/Testing/TestResponse.php on lines 1273..1282

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 97.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                      if (is_null($value)) {
                          PHPUnit::assertTrue(
                              $this->session()->has($key),
                              "Session is missing expected key [{$key}]."
                          );
              Severity: Minor
              Found in src/Illuminate/Testing/TestResponse.php and 1 other location - About 50 mins to fix
              src/Illuminate/Testing/TestResponse.php on lines 1327..1336

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 97.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public function assertSeeText($value, $escape = true)
                  {
                      $value = Arr::wrap($value);
              
                      $values = $escape ? array_map('e', $value) : $value;
              Severity: Minor
              Found in src/Illuminate/Testing/TestResponse.php and 1 other location - About 45 mins to fix
              src/Illuminate/Testing/TestResponse.php on lines 658..671

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 95.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                  public function assertDontSeeText($value, $escape = true)
                  {
                      $value = Arr::wrap($value);
              
                      $values = $escape ? array_map('e', $value) : $value;
              Severity: Minor
              Found in src/Illuminate/Testing/TestResponse.php and 1 other location - About 45 mins to fix
              src/Illuminate/Testing/TestResponse.php on lines 600..613

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 95.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status