uruba/FinanCalc

View on GitHub
src/Utils/Time/TimeSpan.php

Summary

Maintainability
A
2 hrs
Test Coverage

TimeSpan has 21 functions (exceeds 20 allowed). Consider refactoring.
Open

    class TimeSpan
    {
        /** @var  DateTime */
        private $startDate;
        /** @var  DateTime */
Severity: Minor
Found in src/Utils/Time/TimeSpan.php - About 2 hrs to fix

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

                } else {
                    throw new InvalidArgumentException(ErrorMessages::getStartDateMustBeBeforeEndDateMessage());
                }
    Severity: Minor
    Found in src/Utils/Time/TimeSpan.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

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

                } else {
                    $endDate = clone $startDate;
                    $this->endDate = $endDate->add($this->dateInterval);
                }
    Severity: Minor
    Found in src/Utils/Time/TimeSpan.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

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

                } else {
                    $dateInterval = $this->dateInterval;
                    $dateInterval->invert = 1;
                    $startDate = clone $endDate;
                    $this->startDate = $startDate->add($dateInterval);
    Severity: Minor
    Found in src/Utils/Time/TimeSpan.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 unused private methods such as 'newDateIntervalAbsolute'.
    Open

            private function newDateIntervalAbsolute($years, $months, $days)
            {
                $this->setDateInterval(
                    new DateInterval(
                        "P" .
    Severity: Minor
    Found in src/Utils/Time/TimeSpan.php by phpmd

    UnusedPrivateMethod

    Since: 0.2

    Unused Private Method detects when a private method is declared but is unused.

    Example

    class Something
    {
        private function foo() {} // unused
    }

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

    TODO found
    Open

                // TODO: make more intelligent rounding based on the start and end date
    Severity: Minor
    Found in src/Utils/Time/TimeSpan.php by fixme

    Function closing brace must go on the next line following the body; found 1 blank lines before brace
    Open

            }
    Severity: Minor
    Found in src/Utils/Time/TimeSpan.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status