src/SchemaProcessor/PostProcessor/Internal/CompositionValidationPostProcessor.php
Function generateValidatorPropertyMap
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
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
- Read upRead up
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
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
Open
public function getCode(PropertyInterface $property, bool $batchUpdate = false): string
- Read upRead up
- Exclude checks
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
Open
public function getCode(PropertyInterface $property, bool $batchUpdate = false): string
- Read upRead up
- Exclude checks
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
Open
))
- Exclude checks
Closing brace must be on a line by itself Open
Open
public function __construct(protected array $validatorPropertyMap) {}
- Exclude checks
Opening brace should be on a new line Open
Open
public function __construct(protected array $validatorPropertyMap) {}
- Exclude checks
Multi-line function call not indented correctly; expected 24 spaces but found 28 Open
Open
sprintf('$this->validateComposition_%s($modelData);', $validatorIndex),
- Exclude checks
Line indented incorrectly; expected 16 spaces, found 24 Open
Open
static fn(int $validatorIndex): string =>
- Exclude checks