fisharebest/webtrees

View on GitHub
app/Validator.php

Summary

Maintainability
B
5 hrs
Test Coverage

Validator has 21 functions (exceeds 20 allowed). Consider refactoring.
Open

class Validator
{
    /** @var array<int|string|Tree|UserInterface|array<int|string>> */
    private array $parameters;

Severity: Minor
Found in app/Validator.php - About 2 hrs to fix

    Function isXref has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        public function isXref(): self
        {
            $this->rules[] = static function ($value) {
                if (is_string($value) && preg_match('/^' . Gedcom::REGEX_XREF . '$/', $value) === 1) {
                    return $value;
    Severity: Minor
    Found in app/Validator.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 isLocalUrl has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function isLocalUrl(): self
        {
            $base_url = $this->request->getAttribute('base_url', '');
    
            $this->rules[] = static function (string|null $value) use ($base_url): string|null {
    Severity: Minor
    Found in app/Validator.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 __construct has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        private function __construct(array $parameters, ServerRequestInterface $request, string $encoding)
        {
            if ($encoding === 'UTF-8') {
                // All keys and values must be valid UTF-8
                $check_utf8 = static function ($value, $key): void {
    Severity: Minor
    Found in app/Validator.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 integer has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function integer(string $parameter, int|null $default = null): int
        {
            $value = $this->parameters[$parameter] ?? null;
    
            if (is_string($value)) {
    Severity: Minor
    Found in app/Validator.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;
    Severity: Major
    Found in app/Validator.php - About 30 mins to fix

      There are no issues that match your filters.

      Category
      Status