wol-soft/php-json-schema-model-generator

View on GitHub
src/SchemaProcessor/PostProcessor/Internal/CompositionValidationPostProcessor.php

Summary

Maintainability
A
3 hrs
Test Coverage
A
100%

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

    private function generateValidatorPropertyMap(Schema $schema): array
    {
        $validatorPropertyMap = [];

        // get all base validators which are composed value validators and set up a map of affected object properties

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 generateValidatorPropertyMap has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function generateValidatorPropertyMap(Schema $schema): array
    {
        $validatorPropertyMap = [];

        // get all base validators which are composed value validators and set up a map of affected object properties

    The method addValidationCallsToSetterMethods has a boolean flag argument $batchUpdate, which is a certain sign of a Single Responsibility Principle violation.
    Open

                public function getCode(PropertyInterface $property, bool $batchUpdate = false): string

    BooleanArgumentFlag

    Since: 1.4.0

    A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

    Example

    class Foo {
        public function bar($flag = true) {
        }
    }

    Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

    Avoid unused parameters such as '$batchUpdate'.
    Open

                public function getCode(PropertyInterface $property, bool $batchUpdate = false): string

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    syntax error, unexpected ')'
    Open

                    ))

    Closing brace must be on a line by itself
    Open

                public function __construct(protected array $validatorPropertyMap) {}

    Opening brace should be on a new line
    Open

                public function __construct(protected array $validatorPropertyMap) {}

    Multi-line function call not indented correctly; expected 24 spaces but found 28
    Open

                                sprintf('$this->validateComposition_%s($modelData);', $validatorIndex),

    Line indented incorrectly; expected 16 spaces, found 24
    Open

                            static fn(int $validatorIndex): string =>

    There are no issues that match your filters.

    Category
    Status