jon48/webtrees-lib

View on GitHub
app/Module/AdminTasks/Services/TaskScheduleService.php

Summary

Maintainability
B
4 hrs
Test Coverage

The class TaskScheduleService has 11 public methods. Consider refactoring TaskScheduleService to keep number of public methods under 10.
Open

class TaskScheduleService
{
    /**
     * Time-out after which the task will be considered not running any more.
     * In seconds, default 5 mins.

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

Function run has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function run(TaskSchedule $task_schedule, $force = false): void
    {
        /** @var TaskSchedule $task_schedule */
        $task_schedule = DB::table('maj_admintasks')
            ->select()
Severity: Minor
Found in app/Module/AdminTasks/Services/TaskScheduleService.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 run has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function run(TaskSchedule $task_schedule, $force = false): void
    {
        /** @var TaskSchedule $task_schedule */
        $task_schedule = DB::table('maj_admintasks')
            ->select()
Severity: Minor
Found in app/Module/AdminTasks/Services/TaskScheduleService.php - About 1 hr to fix

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

        public function all(bool $sync_available = false, bool $include_disabled = true): Collection
        {
            $tasks_schedules = DB::table('maj_admintasks')
                ->select()
                ->get()
    Severity: Minor
    Found in app/Module/AdminTasks/Services/TaskScheduleService.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

    The class TaskScheduleService has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
    Open

    class TaskScheduleService
    {
        /**
         * Time-out after which the task will be considered not running any more.
         * In seconds, default 5 mins.

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

        public function all(bool $sync_available = false, bool $include_disabled = true): Collection

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

        public function all(bool $sync_available = false, bool $include_disabled = true): Collection

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

        public function run(TaskSchedule $task_schedule, $force = false): void

    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 '\Carbon\CarbonImmutable' in method 'rowMapper'.
    Open

                    CarbonImmutable::parse($row->majat_last_run, 'UTC'),

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

                    } else {
                        $this->delete($task_schedule);
                    }

    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 '\Fisharebest\Webtrees\I18N' in method 'run'.
    Open

                            Log::addErrorLog(I18N::translate('Error while running task %s:', $task->name()) . ' ' .

    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 '\Carbon\CarbonImmutable' in method 'run'.
    Open

                        $task_schedule->setLastRunTime(CarbonImmutable::now('UTC'));

    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 '\Fisharebest\Webtrees\Log' in method 'run'.
    Open

                            Log::addErrorLog(I18N::translate('Error while running task %s:', $task->name()) . ' ' .
                                '[' . get_class($ex) . '] ' . $ex->getMessage() . ' ' . $ex->getFile() . ':'
                                . $ex->getLine() . PHP_EOL . $ex->getTraceAsString());

    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 assigning values to variables in if clauses and the like (line '84', column '30').
    Open

        public function all(bool $sync_available = false, bool $include_disabled = true): Collection
        {
            $tasks_schedules = DB::table('maj_admintasks')
                ->select()
                ->get()

    IfStatementAssignment

    Since: 2.7.0

    Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($foo = 'bar') { // possible typo
                // ...
            }
            if ($baz = 0) { // always false
                // ...
            }
        }
    }

    Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

    Avoid using static access to class '\Carbon\CarbonImmutable' in method 'run'.
    Open

                        ->lessThan(CarbonImmutable::now('UTC'))

    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

    There are no issues that match your filters.

    Category
    Status