sebastianmonzel/webfiles-framework-php

View on GitHub
source/core/datasystem/file/format/MWebfile.php

Summary

Maintainability
D
2 days
Test Coverage
F
58%

Function getDatatypeFromAttributeName has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getDatatypeFromAttributeName($attributeName)
    {
        $typeIdentifier = self::getTypeIdentifier($attributeName);

        if ($typeIdentifier == "s") {
Severity: Minor
Found in source/core/datasystem/file/format/MWebfile.php - About 6 hrs 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

File MWebfile.php has 333 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace webfilesframework\core\datasystem\file\format;
use ReflectionClass;
use ReflectionException;
Severity: Minor
Found in source/core/datasystem/file/format/MWebfile.php - About 4 hrs to fix

MWebfile has 28 functions (exceeds 20 allowed). Consider refactoring.
Open

class MWebfile {

    protected $m_iId = 0;

    /**
Severity: Minor
Found in source/core/datasystem/file/format/MWebfile.php - About 3 hrs to fix

The class MWebfile has an overall complexity of 80 which is very high. The configured complexity threshold is 50.
Open

class MWebfile {

    protected $m_iId = 0;

    /**

Function matchesTemplate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function matchesTemplate(MWebfile $template) {

        if ( $template::classname() == static::classname() ) {

            $attributes = $template->getAttributes(true);
Severity: Minor
Found in source/core/datasystem/file/format/MWebfile.php - About 1 hr 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 genericXmlUnmarshal has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    private static function genericXmlUnmarshal($xmlAsString, $targetObject): object
    {
        $root = simplexml_load_string($xmlAsString);

        if ($root == null) {
Severity: Minor
Found in source/core/datasystem/file/format/MWebfile.php - About 1 hr 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

Method genericXmlUnmarshal has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private static function genericXmlUnmarshal($xmlAsString, $targetObject): object
    {
        $root = simplexml_load_string($xmlAsString);

        if ($root == null) {
Severity: Minor
Found in source/core/datasystem/file/format/MWebfile.php - About 1 hr to fix

Function genericJsonUnmarshal has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    private static function genericJsonUnmarshal($input, $targetObject): object
    {
        // TODO probleme mit zeilen umbrüchen
        if ( is_array($input) ) {
            // already parsed json
Severity: Minor
Found in source/core/datasystem/file/format/MWebfile.php - About 1 hr 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 marshalAsJson has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function marshalAsJson(): string
    {
        $json = "";
        $attributes = $this->getAttributes();
        $json .= "{\n";
Severity: Minor
Found in source/core/datasystem/file/format/MWebfile.php - About 1 hr 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 null;
Severity: Major
Found in source/core/datasystem/file/format/MWebfile.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return "object";
Severity: Major
Found in source/core/datasystem/file/format/MWebfile.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return "integer";
Severity: Major
Found in source/core/datasystem/file/format/MWebfile.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return "time";
Severity: Major
Found in source/core/datasystem/file/format/MWebfile.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return "float";
Severity: Major
Found in source/core/datasystem/file/format/MWebfile.php - About 30 mins to fix

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

    public static function getAttributes($simpleDatatypesOnly = 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

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

    public function marshall($usePreamble = true, $marshallAsJSON = 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

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

    public function marshall($usePreamble = true, $marshallAsJSON = 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 using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'genericXmlUnmarshal'.
Open

            $targetObject = MWebfile::createWebfileByClassname($classname);

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

Avoid using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'getClassInformation'.
Open

            if (MWebfile::isSimpleDatatypeAttribute($attributeName)) {

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

Avoid using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'getClassInformation'.
Open

                $attributeFieldType = MWebfile::getDatatypeFromAttributeName($attributeName);

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

The method genericJsonUnmarshal uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            // json string
            $jsonRoot = json_decode($input, true);
        }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

The method isSimpleDatatypeAttribute uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            return false;
        }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'getDataset'.
Open

            if (MWebfile::isSimpleDatatypeAttribute($attributeName)) {

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

Avoid using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'presetForTemplateSearch'.
Open

            if (MWebfile::isSimpleDatatypeAttribute($attributeName)) {

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

Avoid using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'marshalAsJson'.
Open

            if (MWebfile::isSimpleDatatypeAttribute($attributeName)) {

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

The method marshalAsJson uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $json .= "\t\t\"" . $attributeFieldName . "\": \"" . $attributeFieldValue . "\"";
                }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

The method matchesTemplate uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            return false;
        }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'marshalAsXml'.
Open

            if (MWebfile::isSimpleDatatypeAttribute($attributeName)) {

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

The method marshall uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            return $this->marshalAsJson();
        }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

The method genericUnmarshall uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            // xml as text
            return self::genericXmlUnmarshal($input, $targetObject);
        }

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

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

Avoid using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'genericJsonUnmarshal'.
Open

            $targetObject = MWebfile::createWebfileByClassname($classname);

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

Avoid using static access to class 'webfilesframework\core\datasystem\file\format\MWebfile' in method 'getSimplifiedObject'.
Open

            if (MWebfile::isSimpleDatatypeAttribute($attributeName)) {

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

Avoid unused local variables such as '$key'.
Open

        foreach ($attributes as $key => $attribute) {

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

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

Avoid using webfilesframework\core\datasystem\file\format\count() function in while loops.
Open

        while ($count < count($oPropertyArray)) {
            $sAttributeName = $oPropertyArray[$count]->getName();
            if (
                // TODO generalize attribute prefix (sample "m_-s-", (start 2, length 1) )
                substr($sAttributeName, 1, 1) != "_" ||

CountInLoopExpression

Since: 2.7.0

Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.

Example

class Foo {

  public function bar()
  {
    $array = array();

    for ($i = 0; count($array); $i++) {
      // ...
    }
  }
}

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

TODO found
Open

        // TODO probleme mit zeilen umbrüchen

TODO found
Open

        // TODO generalize attribute prefix (sample "m_-s-", (start 2, length 1) )

TODO found
Open

                // TODO generalize attribute prefix (sample "m_-s-", (start 2, length 1) )

TODO found
Open

                    $json .= "\t\t\"" . $attributeFieldName . "\": " . $attributeFieldValue; // TODO check if value is really numeric?

Avoid excessively long variable names like $simplifiedAttributeName. Keep variable name length under 20.
Open

        $simplifiedAttributeName = substr($originAttributeName, 3);

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

The property $m_iId is not named in camelCase.
Open

class MWebfile {

    protected $m_iId = 0;

    /**

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $m_iTime is not named in camelCase.
Open

class MWebfile {

    protected $m_iId = 0;

    /**

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

There are no issues that match your filters.

Category
Status