laravel/framework

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

Summary

Maintainability
C
1 day
Test Coverage

Function getFromLocalArray has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    protected function getFromLocalArray($attribute, $lowerRule, $source = null)
    {
        $source = $source ?: $this->customMessages;

        $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute];
Severity: Minor
Found in src/Illuminate/Validation/Concerns/FormatsMessages.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

File FormatsMessages.php has 262 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Illuminate\Validation\Concerns;

use Closure;
Severity: Minor
Found in src/Illuminate/Validation/Concerns/FormatsMessages.php - About 2 hrs to fix

    Method getMessage has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function getMessage($attribute, $rule)
        {
            $attributeWithPlaceholders = $attribute;
    
            $attribute = $this->replacePlaceholderInString($attribute);
    Severity: Minor
    Found in src/Illuminate/Validation/Concerns/FormatsMessages.php - About 1 hr to fix

      Method callClassBasedReplacer has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          protected function callClassBasedReplacer($callback, $message, $attribute, $rule, $parameters, $validator)
      Severity: Minor
      Found in src/Illuminate/Validation/Concerns/FormatsMessages.php - About 45 mins to fix

        Method callReplacer has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            protected function callReplacer($message, $attribute, $rule, $parameters, $validator)
        Severity: Minor
        Found in src/Illuminate/Validation/Concerns/FormatsMessages.php - About 35 mins to fix

          Avoid too many return statements within this method.
          Open

                  return (string) $value;
          Severity: Major
          Found in src/Illuminate/Validation/Concerns/FormatsMessages.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return $this->getFromLocalArray(
                        $attribute, $lowerRule, $this->fallbackMessages
                    ) ?: $key;
            Severity: Major
            Found in src/Illuminate/Validation/Concerns/FormatsMessages.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

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

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

                    public function getDisplayableAttribute($attribute)
                    {
                        $primaryAttribute = $this->getPrimaryAttribute($attribute);
                
                        $expectedAttributes = $attribute != $primaryAttribute
                Severity: Minor
                Found in src/Illuminate/Validation/Concerns/FormatsMessages.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 replaceIndexOrPositionPlaceholder has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function replaceIndexOrPositionPlaceholder($message, $attribute, $placeholder, Closure $modifier = null)
                    {
                        $segments = explode('.', $attribute);
                
                        $modifier ??= fn ($value) => $value;
                Severity: Minor
                Found in src/Illuminate/Validation/Concerns/FormatsMessages.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