imanghafoori1/laravel-widgetize

View on GitHub
src/Utils/WidgetRenderer.php

Summary

Maintainability
A
0 mins
Test Coverage

Missing class import via use statement (line '133', column '23').
Open

            throw new \ErrorException('There was some error rendering '.get_class($widget).', template file: \''.$widget->template.'\' Error: '.$t->getMessage());
Severity: Minor
Found in src/Utils/WidgetRenderer.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

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

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

        } else {
            $this->_viewData = resolve(Cache::class)->cacheResult($args, $expensiveCode, $widget, 'dataProvider');
        }
Severity: Minor
Found in src/Utils/WidgetRenderer.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 '\App' in method 'callController'.
Open

            $viewData = \App::call($widget->controller, ...$args);
Severity: Minor
Found in src/Utils/WidgetRenderer.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 '\App' in method 'makeDataForView'.
Open

                $viewData = \App::call($widget->presenter, [$viewData]);
Severity: Minor
Found in src/Utils/WidgetRenderer.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 callController uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            // Here we call the data method on the widget class.
            $viewData = \App::call($widget->controller, ...$args);
        }
Severity: Minor
Found in src/Utils/WidgetRenderer.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 '\Illuminate\Support\Str' in method 'makeWidgetObj'.
Open

        if (Str::startsWith($widget, ['\\'])) {
Severity: Minor
Found in src/Utils/WidgetRenderer.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

Define and throw a dedicated exception instead of using a generic one.
Open

            throw new \ErrorException('There was some error rendering '.get_class($widget).', template file: \''.$widget->template.'\' Error: '.$t->getMessage());
Severity: Major
Found in src/Utils/WidgetRenderer.php by sonar-php

If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

Noncompliant Code Example

throw new Exception();  // Noncompliant

Compliant Solution

throw new InvalidArgumentException();
// or
throw new UnexpectedValueException();

See

The property $_viewData is not named in camelCase.
Open

class WidgetRenderer
{
    use SlotRenderer;

    public $html;
Severity: Minor
Found in src/Utils/WidgetRenderer.php by phpmd

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

The property $_policies is not named in camelCase.
Open

class WidgetRenderer
{
    use SlotRenderer;

    public $html;
Severity: Minor
Found in src/Utils/WidgetRenderer.php by phpmd

CamelCasePropertyName

Since: 0.2

It is considered best practice to use the camelCase notation to name attributes.

Example

class ClassName {
    protected $property_name;
}

Source

Property name "$_policies" should not be prefixed with an underscore to indicate visibility
Open

    private $_policies;
Severity: Minor
Found in src/Utils/WidgetRenderer.php by phpcodesniffer

Property name "$_viewData" should not be prefixed with an underscore to indicate visibility
Open

    private $_viewData;
Severity: Minor
Found in src/Utils/WidgetRenderer.php by phpcodesniffer

Line exceeds 120 characters; contains 162 characters
Open

            throw new \ErrorException('There was some error rendering '.get_class($widget).', template file: \''.$widget->template.'\' Error: '.$t->getMessage());
Severity: Minor
Found in src/Utils/WidgetRenderer.php by phpcodesniffer

There are no issues that match your filters.

Category
Status