laravel/framework

View on GitHub
src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Summary

Maintainability
F
5 days
Test Coverage

File ValidatesAttributes.php has 1197 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Illuminate\Validation\Concerns;

use Brick\Math\BigDecimal;
Severity: Major
Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 3 days to fix

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

        protected function failsBasicDimensionChecks($parameters, $width, $height)
        {
            return (isset($parameters['width']) && $parameters['width'] != $width) ||
                   (isset($parameters['min_width']) && $parameters['min_width'] > $width) ||
                   (isset($parameters['max_width']) && $parameters['max_width'] < $width) ||
    Severity: Minor
    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.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 getExistCount has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        protected function getExistCount($connection, $table, $column, $value, $parameters)
    Severity: Minor
    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 35 mins to fix

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

          public function validateDateFormat($attribute, $value, $parameters)
          {
              $this->requireParameterCount(1, $parameters, 'date_format');
      
              if (! is_string($value) && ! is_numeric($value)) {
      Severity: Minor
      Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.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 validateActiveUrl has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function validateActiveUrl($attribute, $value)
          {
              if (! is_string($value)) {
                  return false;
              }
      Severity: Minor
      Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.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 validateIn has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function validateIn($attribute, $value, $parameters)
          {
              if (is_array($value) && $this->hasRule($attribute, 'Array')) {
                  foreach ($value as $element) {
                      if (is_array($element)) {
      Severity: Minor
      Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.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 validateMultipleOf has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public function validateMultipleOf($attribute, $value, $parameters)
          {
              $this->requireParameterCount(1, $parameters, 'multiple_of');
      
              if (! $this->validateNumeric($attribute, $value) || ! $this->validateNumeric($attribute, $parameters[0])) {
      Severity: Minor
      Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.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 $this->getSize($attribute, $value) >= $this->getSize($attribute, $comparedToValue);
      Severity: Major
      Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                return $this->getSize($attribute, $value) > $this->getSize($attribute, $comparedToValue);
        Severity: Major
        Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return $numerator->remainder($denominator)->isZero();
          Severity: Major
          Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return $this->getSize($attribute, $value) < $this->getSize($attribute, $comparedToValue);
            Severity: Major
            Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $this->getSize($attribute, $value) <= $this->getSize($attribute, $comparedToValue);
              Severity: Major
              Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return true;
                Severity: Major
                Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return true;
                  Severity: Major
                  Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php - About 30 mins to fix

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

                        public function validateDifferent($attribute, $value, $parameters)
                        {
                            $this->requireParameterCount(1, $parameters, 'different');
                    
                            foreach ($parameters as $parameter) {
                    Severity: Minor
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.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 validateProhibits has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function validateProhibits($attribute, $value, $parameters)
                        {
                            if ($this->validateRequired($attribute, $value)) {
                                foreach ($parameters as $parameter) {
                                    if ($this->validateRequired($parameter, Arr::get($this->data, $parameter))) {
                    Severity: Minor
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.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 validateDimensions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function validateDimensions($attribute, $value, $parameters)
                        {
                            if ($this->isValidFileInstance($value) && in_array($value->getMimeType(), ['image/svg+xml', 'image/svg'])) {
                                return true;
                            }
                    Severity: Minor
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.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

                        public function validateAcceptedIf($attribute, $value, $parameters)
                        {
                            $acceptable = ['yes', 'on', '1', 1, true, 'true'];
                    
                            $this->requireParameterCount(2, $parameters, 'accepted_if');
                    Severity: Major
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php and 1 other location - About 3 hrs to fix
                    src/Illuminate/Validation/Concerns/ValidatesAttributes.php on lines 97..110

                    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 154.

                    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 validateDeclinedIf($attribute, $value, $parameters)
                        {
                            $acceptable = ['no', 'off', '0', 0, false, 'false'];
                    
                            $this->requireParameterCount(2, $parameters, 'declined_if');
                    Severity: Major
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php and 1 other location - About 3 hrs to fix
                    src/Illuminate/Validation/Concerns/ValidatesAttributes.php on lines 58..71

                    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 154.

                    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 validateRequiredUnless($attribute, $value, $parameters)
                        {
                            $this->requireParameterCount(2, $parameters, 'required_unless');
                    
                            [$values, $other] = $this->parseDependentRuleParameters($parameters);
                    Severity: Major
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php and 1 other location - About 1 hr to fix
                    src/Illuminate/Validation/Concerns/ValidatesAttributes.php on lines 1809..1820

                    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 107.

                    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 validatePresentUnless($attribute, $value, $parameters)
                        {
                            $this->requireParameterCount(2, $parameters, 'present_unless');
                    
                            [$values, $other] = $this->parseDependentRuleParameters($parameters);
                    Severity: Major
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php and 1 other location - About 1 hr to fix
                    src/Illuminate/Validation/Concerns/ValidatesAttributes.php on lines 2095..2106

                    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 107.

                    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 validateAlphaDash($attribute, $value, $parameters)
                        {
                            if (! is_string($value) && ! is_numeric($value)) {
                                return false;
                            }
                    Severity: Major
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php and 1 other location - About 1 hr to fix
                    src/Illuminate/Validation/Concerns/ValidatesAttributes.php on lines 390..401

                    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 106.

                    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 validateAlphaNum($attribute, $value, $parameters)
                        {
                            if (! is_string($value) && ! is_numeric($value)) {
                                return false;
                            }
                    Severity: Major
                    Found in src/Illuminate/Validation/Concerns/ValidatesAttributes.php and 1 other location - About 1 hr to fix
                    src/Illuminate/Validation/Concerns/ValidatesAttributes.php on lines 369..380

                    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 106.

                    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