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

View on GitHub
src/PropertyProcessor/Property/AbstractPropertyProcessor.php

Summary

Maintainability
A
3 hrs
Test Coverage
A
100%

Method addComposedValueValidator has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function addComposedValueValidator(PropertyInterface $property, JsonSchema $propertySchema): void
    {
        $composedValueKeywords = ['allOf', 'anyOf', 'oneOf', 'not', 'if'];
        $propertyFactory = new PropertyFactory(new ComposedValueProcessorFactory($property instanceof BaseProperty));

Severity: Minor
Found in src/PropertyProcessor/Property/AbstractPropertyProcessor.php - About 1 hr to fix

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

        protected function addComposedValueValidator(PropertyInterface $property, JsonSchema $propertySchema): void
        {
            $composedValueKeywords = ['allOf', 'anyOf', 'oneOf', 'not', 'if'];
            $propertyFactory = new PropertyFactory(new ComposedValueProcessorFactory($property instanceof BaseProperty));
    
    
    Severity: Minor
    Found in src/PropertyProcessor/Property/AbstractPropertyProcessor.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 inheritPropertyType has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function inheritPropertyType(JsonSchema $propertySchema, string $composedValueKeyword): JsonSchema
        {
            $json = $propertySchema->getJson();
    
            if (!isset($json['type'])) {
    Severity: Minor
    Found in src/PropertyProcessor/Property/AbstractPropertyProcessor.php - About 45 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 inheritIfPropertyType has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function inheritIfPropertyType(JsonSchema $propertySchema): JsonSchema
        {
            $json = $propertySchema->getJson();
    
            foreach (['if', 'then', 'else'] as $composedValueKeyword) {
    Severity: Minor
    Found in src/PropertyProcessor/Property/AbstractPropertyProcessor.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 addEnumValidator has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function addEnumValidator(PropertyInterface $property, array $allowedValues): void
        {
            if (empty($allowedValues)) {
                throw new SchemaException(
                    sprintf(
    Severity: Minor
    Found in src/PropertyProcessor/Property/AbstractPropertyProcessor.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

    The class AbstractPropertyProcessor has a coupling between objects value of 19. Consider to reduce the number of dependencies under 13.
    Open

    abstract class AbstractPropertyProcessor implements PropertyProcessorInterface
    {
        public function __construct(
            protected PropertyMetaDataCollection $propertyMetaDataCollection,
            protected SchemaProcessor $schemaProcessor,

    CouplingBetweenObjects

    Since: 1.1.0

    A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

    Example

    class Foo {
        /**
         * @var \foo\bar\X
         */
        private $x = null;
    
        /**
         * @var \foo\bar\Y
         */
        private $y = null;
    
        /**
         * @var \foo\bar\Z
         */
        private $z = null;
    
        public function setFoo(\Foo $foo) {}
        public function setBar(\Bar $bar) {}
        public function setBaz(\Baz $baz) {}
    
        /**
         * @return \SplObjectStorage
         * @throws \OutOfRangeException
         * @throws \InvalidArgumentException
         * @throws \ErrorException
         */
        public function process(\Iterator $it) {}
    
        // ...
    }

    Source https://phpmd.org/rules/design.html#couplingbetweenobjects

    Avoid assigning values to variables in if clauses and the like (line '47', column '13').
    Open

        protected function generateValidators(PropertyInterface $property, JsonSchema $propertySchema): void
        {
            if ($dependencies = $this->propertyMetaDataCollection->getAttributeDependencies($property->getName())) {
                $this->addDependencyValidator($property, $dependencies);
            }

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class '\PHPModelGenerator\Utils\TypeConverter' in method 'addEnumValidator'.
    Open

                    static fn($value): string => TypeConverter::gettypeToInternal(gettype($value)),

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)
    Open

            protected PropertyMetaDataCollection $propertyMetaDataCollection,

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            protected Schema $schema

    Line indented incorrectly; expected 12 spaces, found 16
    Open

                    static fn($value): string => TypeConverter::gettypeToInternal(gettype($value)),

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                static function ($dependency, $index) use (&$propertyDependency): void {

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            protected PropertyMetaDataCollection $propertyMetaDataCollection,

    Line indented incorrectly; expected 4 spaces, found 8
    Open

            protected SchemaProcessor $schemaProcessor,

    Line indented incorrectly; expected 8 spaces, found 12
    Open

                },

    Closing brace must be on a line by itself
    Open

        ) {}

    There are no issues that match your filters.

    Category
    Status