jon48/webtrees-lib

View on GitHub
app/Module/IsSourced/Data/FactSourceStatus.php

Summary

Maintainability
A
3 hrs
Test Coverage

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

class FactSourceStatus extends SourceStatus
{
    /**
     * @var boolean $has_date
     */

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 label has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function label(string $context): string
    {
        $context_label = Registry::elementFactory()->make($context)->label();

        if ($this->factHasPreciseDate()) {
Severity: Minor
Found in app/Module/IsSourced/Data/FactSourceStatus.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 I18N::translate('%s not sourced', $context_label);
Severity: Major
Found in app/Module/IsSourced/Data/FactSourceStatus.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

                return I18N::translate('%s not precise', $context_label);
    Severity: Major
    Found in app/Module/IsSourced/Data/FactSourceStatus.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              return I18N::translate('%s not found', $context_label);
      Severity: Major
      Found in app/Module/IsSourced/Data/FactSourceStatus.php - About 30 mins to fix

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

                            } else {
                                return I18N::translate('%s sourced with a certificate', $context_label);
                            }

        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 'label'.
        Open

                                return I18N::translate('%s sourced with a certificate', $context_label);

        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\I18N' in method 'label'.
        Open

                    return I18N::translate('%s not sourced', $context_label);

        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\I18N' in method 'label'.
        Open

                    return I18N::translate('%s not precise', $context_label);

        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\I18N' in method 'label'.
        Open

                                return I18N::translate('%s sourced with exact certificate', $context_label);

        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\I18N' in method 'label'.
        Open

                            return I18N::translate('%s precisely sourced', $context_label);

        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\I18N' in method 'label'.
        Open

                return I18N::translate('%s not found', $context_label);

        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\I18N' in method 'label'.
        Open

                        return I18N::translate('%s sourced', $context_label);

        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