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

View on GitHub
src/SchemaProcessor/SchemaProcessor.php

Summary

Maintainability
A
3 hrs
Test Coverage
A
100%

Method createMergedProperty has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function createMergedProperty(
        Schema $schema,
        PropertyInterface $property,
        array $compositionProperties,
        JsonSchema $propertySchema,
Severity: Minor
Found in src/SchemaProcessor/SchemaProcessor.php - About 1 hr to fix

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

            string $classPath,
            string $className,
            JsonSchema $jsonSchema,
            SchemaDefinitionDictionary $dictionary,
            bool $initialClass,
    Severity: Minor
    Found in src/SchemaProcessor/SchemaProcessor.php - About 35 mins to fix

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

              JsonSchema $jsonSchema,
              string $classPath,
              string $className,
              SchemaDefinitionDictionary $dictionary,
              bool $initialClass = false,
      Severity: Minor
      Found in src/SchemaProcessor/SchemaProcessor.php - About 35 mins to fix

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

            private function redirectMergedProperty(array $compositionProperties)
            {
                $redirectToProperty = null;
                foreach ($compositionProperties as $property) {
                    if ($property->getNestedSchema()) {
        Severity: Minor
        Found in src/SchemaProcessor/SchemaProcessor.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 SchemaProcessor has a coupling between objects value of 18. Consider to reduce the number of dependencies under 13.
        Open

        class SchemaProcessor
        {
            /** @var GeneratorConfiguration */
            protected $generatorConfiguration;
            /** @var RenderQueue */

        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

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

                bool $initialClass = false,

        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 '$schema'.
        Open

                Schema $schema,

        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 ')', expecting variable (T_VARIABLE)
        Open

            ) {
        Severity: Critical
        Found in src/SchemaProcessor/SchemaProcessor.php by phan

        Arguments with default values must be at the end of the argument list
        Open

                bool $initialClass = false,

        Multi-line function call not indented correctly; expected 16 spaces but found 20
        Open

                            new PropertyType($mergedClassName),

        Multi-line function call not indented correctly; expected 12 spaces but found 16
        Open

                        ))

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    },

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

                                // corresponding to the defined constraints of the composition property.

        Multi-line function call not indented correctly; expected 16 spaces but found 20
        Open

                            'MergedProperty',

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

                                // don't validate fields in merged properties. All fields were validated before

        Line indented incorrectly; expected 8 spaces, found 12
        Open

                    static function (string $directory): string {

        Multi-line function call not indented correctly; expected 16 spaces but found 20
        Open

                            $mergedPropertySchema->getJsonSchema(),

        There are no issues that match your filters.

        Category
        Status