YetiForceCompany/YetiForcePDF

View on GitHub
lib/Layout/ImageBox.php

Summary

Maintainability
A
25 mins
Test Coverage

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

    public function measureWidth(bool $afterPageDividing = false)
    {
        $style = $this->getStyle();
        if ('auto' === $style->getRules('width')) {
            $img = $style->getBackgroundImageStream();
Severity: Minor
Found in lib/Layout/ImageBox.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 method measureHeight has a boolean flag argument $afterPageDividing, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function measureHeight(bool $afterPageDividing = false)
Severity: Minor
Found in lib/Layout/ImageBox.php by phpmd

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 measureWidth has a boolean flag argument $afterPageDividing, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function measureWidth(bool $afterPageDividing = false)
Severity: Minor
Found in lib/Layout/ImageBox.php by phpmd

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 '\YetiForcePDF\Math' in method 'measureWidth'.
Open

                Math::setAccurate(false);
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid using static access to class '\YetiForcePDF\Math' in method 'measureWidth'.
Open

            if (Math::comp($width, $this->getParent()->getDimensions()->computeAvailableSpace()) > 0) {
Severity: Minor
Found in lib/Layout/ImageBox.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 measureWidth uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $this->applyStyleWidth();
        }
Severity: Minor
Found in lib/Layout/ImageBox.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\Math' in method 'measureWidth'.
Open

                Math::setAccurate(true);
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid using static access to class '\YetiForcePDF\Math' in method 'measureWidth'.
Open

            $width = Math::add($width, $style->getHorizontalBordersWidth(), $style->getHorizontalPaddingsWidth());
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid using static access to class '\YetiForcePDF\Math' in method 'measureWidth'.
Open

                $width = Math::mul($ratio, $this->getDimensions()->getStyleHeight());
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid using static access to class '\YetiForcePDF\Math' in method 'measureHeight'.
Open

        Math::setAccurate(true);
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid using static access to class '\YetiForcePDF\Math' in method 'measureHeight'.
Open

        $height = Math::div($this->getDimensions()->getInnerWidth(), $ratio);
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid using static access to class '\YetiForcePDF\Math' in method 'measureHeight'.
Open

        Math::setAccurate(false);
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid using static access to class '\YetiForcePDF\Math' in method 'measureHeight'.
Open

        $height = Math::add($height, $style->getVerticalBordersWidth(), $style->getVerticalPaddingsWidth());
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid unused parameters such as '$afterPageDividing'.
Open

    public function measureHeight(bool $afterPageDividing = false)
Severity: Minor
Found in lib/Layout/ImageBox.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

Avoid unused parameters such as '$afterPageDividing'.
Open

    public function measureWidth(bool $afterPageDividing = false)
Severity: Minor
Found in lib/Layout/ImageBox.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

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

            if (Math::comp($width, $this->getParent()->getDimensions()->computeAvailableSpace()) > 0) {
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     *
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        $style = $this->getStyle();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        $img = $style->getBackgroundImageStream();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        return $this;
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

            $img = $style->getBackgroundImageStream();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

            if ('auto' !== $style->getRules('height')) {
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        }
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     * @return $this
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

    {
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

            }
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     * @param bool $afterPageDividing
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        $this->getDimensions()->setHeight($height);
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     * Measure width.
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     * @return $this
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

            $width = Math::add($width, $style->getHorizontalBordersWidth(), $style->getHorizontalPaddingsWidth());
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

            $this->applyStyleWidth();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     * Measure height.
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     *
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

    public function measureHeight(bool $afterPageDividing = false)
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

                $width = Math::mul($ratio, $this->getDimensions()->getStyleHeight());
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

                Math::setAccurate(false);
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

            }
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     * @param bool $afterPageDividing
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        return $this;
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     */
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        $ratio = $img->getRatio();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     *
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        if ('auto' === $style->getRules('width')) {
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

                Math::setAccurate(true);
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

    public function measureWidth(bool $afterPageDividing = false)
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        $style = $this->getStyle();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

    }
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     */
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        $height = Math::div($this->getDimensions()->getInnerWidth(), $ratio);
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        Math::setAccurate(false);
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        Math::setAccurate(true);
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

    /**
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

                $ratio = $img->getRatio();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        } else {
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

        $height = Math::add($height, $style->getVerticalBordersWidth(), $style->getVerticalPaddingsWidth());
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

    /**
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

     *
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

    {
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

            $width = $img->getWidth();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

                $width = $this->getParent()->getDimensions()->computeAvailableSpace();
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

            $this->getDimensions()->setWidth($width);
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

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

    }
Severity: Minor
Found in lib/Layout/ImageBox.php by phpcodesniffer

There are no issues that match your filters.

Category
Status