YetiForceCompany/YetiForcePDF

View on GitHub
lib/Style/Normalizer/Border.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method normalize has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function normalize($ruleValue, string $ruleName = ''): array
    {
        if (null !== $this->normalized) {
            return $this->normalized;
        }
Severity: Minor
Found in lib/Style/Normalizer/Border.php - About 1 hr to fix

    Function normalize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function normalize($ruleValue, string $ruleName = ''): array
        {
            if (null !== $this->normalized) {
                return $this->normalized;
            }
    Severity: Minor
    Found in lib/Style/Normalizer/Border.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

    Avoid unused parameters such as '$ruleName'.
    Open

        public function normalize($ruleValue, string $ruleName = ''): array
    Severity: Minor
    Found in lib/Style/Normalizer/Border.php by phpmd

    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

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

            } else {
                $color = '#000000';
            }
    Severity: Minor
    Found in lib/Style/Normalizer/Border.php by phpmd

    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 '\YetiForcePDF\Style\Normalizer\Normalizer' in method 'normalize'.
    Open

                $normalizerName = \YetiForcePDF\Style\Normalizer\Normalizer::getNormalizerClassName($normalizedName);
    Severity: Minor
    Found in lib/Style/Normalizer/Border.php by phpmd

    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 normalize uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $style = 'solid';
            }
    Severity: Minor
    Found in lib/Style/Normalizer/Border.php by phpmd

    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

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $normalizedAgain = [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function normalize($ruleValue, string $ruleName = ''): array

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $originalUnit = $matches[2] ?? 0;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (isset($matches[4])) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $normalizer = (new $normalizerName())->setDocument($this->document)->setStyle($this->style)->init();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $normalizedAgain[$name] = $value;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $color = '#000000';

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (null !== $this->normalized) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $normalizerName = \YetiForcePDF\Style\Normalizer\Normalizer::getNormalizerClassName($normalizedName);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $matches = [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'border-width' => $originalSize . $originalUnit,

    Spaces must be used to indent lines; tabs are not allowed
    Open

            foreach ($normalized as $normalizedName => $normalizedValue) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                foreach ($normalizer->normalize($normalizedValue) as $name => $value) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $originalSize = $matches[1] ?? 0;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $style = $matches[3];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $color = $matches[4];

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            preg_match('/([0-9]+)([a-z]+)\s+(solid|dashed|dotted|none)\s+(.+)?/ui', $ruleValue, $matches);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $this->normalized = $normalizedAgain;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'border-style' => $style,

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                return $this->normalized;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (isset($matches[3])) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $normalized = [

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $style = 'solid';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'border-color' => $color,

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    There are no issues that match your filters.

    Category
    Status