imanghafoori1/laravel-widgetize

View on GitHub

Showing 63 of 63 total issues

Avoid using static access to class '\Illuminate\Support\Str' in method 'generateNewToken'.
Open

        $token = Str::random(7);
Severity: Minor
Found in src/Utils/CacheTag.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

Line exceeds 120 characters; contains 125 characters
Open

            throw new \InvalidArgumentException("View file \"{$widget->template}\" not found by: '".get_class($widget)." '");

Line exceeds 120 characters; contains 124 characters
Open

            return ' 
 Cache: is globally turned off (You should put "enable_cache" => true in config\widgetize.php) ';
Severity: Minor
Found in src/Utils/DebugInfo.php by phpcodesniffer

Line exceeds 120 characters; contains 135 characters
Open

        throw new \InvalidArgumentException('Cache Tags on "'.get_class($widget).'" must be of type Array with String elements.'.$tag);

Line exceeds 120 characters; contains 148 characters
Open

        $this->html = "<span title='WidgetObj : ".get_class($this->widget).".php&#013;Template : {$tpl}{$this->cacheState()}'>{$this->html}</span>";
Severity: Minor
Found in src/Utils/DebugInfo.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

Line exceeds 120 characters; contains 143 characters
Open

        $this->html = "<!-- '{".get_class($this->widget)."' Widget Start -->".$this->html."<!-- '".get_class($this->widget)."' Widget End -->";
Severity: Minor
Found in src/Utils/DebugInfo.php by phpcodesniffer

Line exceeds 120 characters; contains 122 characters
Open

            return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->renderWidget{$expression}; ?>";

Line exceeds 120 characters; contains 122 characters
Open

            return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->renderWidget{$expression}; ?>";

Line indented incorrectly; expected at least 8 spaces, found 0
Open

'2 - "$params" (data passed to @widget(\'name\', $params) call). '.PHP_EOL.'
Severity: Minor
Found in src/WidgetGenerator.php by phpcodesniffer

The variable $_key is not named in camelCase.
Open

    private function makeCacheKey(array $arg, $widget, string $form): string
    {
        if (method_exists($widget, 'cacheKey')) {
            return $widget->cacheKey($arg);
        }
Severity: Minor
Found in src/Utils/Cache.php by phpmd

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $_key is not named in camelCase.
Open

    private function makeCacheKey(array $arg, $widget, string $form): string
    {
        if (method_exists($widget, 'cacheKey')) {
            return $widget->cacheKey($arg);
        }
Severity: Minor
Found in src/Utils/Cache.php by phpmd

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $_key is not named in camelCase.
Open

    private function makeCacheKey(array $arg, $widget, string $form): string
    {
        if (method_exists($widget, 'cacheKey')) {
            return $widget->cacheKey($arg);
        }
Severity: Minor
Found in src/Utils/Cache.php by phpmd

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $_key is not named in camelCase.
Open

    private function makeCacheKey(array $arg, $widget, string $form): string
    {
        if (method_exists($widget, 'cacheKey')) {
            return $widget->cacheKey($arg);
        }
Severity: Minor
Found in src/Utils/Cache.php by phpmd

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $M is not named in camelCase.
Open

    public function normalize($widget): void
    {
        if (! property_exists($widget, 'cacheLifeTime')) {
            $M = config('widgetize.default_cache_lifetime', 0);
            $widget->cacheLifeTime = $this->makeFromSeconds($M * 60);

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $_key is not named in camelCase.
Open

    private function makeCacheKey(array $arg, $widget, string $form): string
    {
        if (method_exists($widget, 'cacheKey')) {
            return $widget->cacheKey($arg);
        }
Severity: Minor
Found in src/Utils/Cache.php by phpmd

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $M is not named in camelCase.
Open

    public function normalize($widget): void
    {
        if (! property_exists($widget, 'cacheLifeTime')) {
            $M = config('widgetize.default_cache_lifetime', 0);
            $widget->cacheLifeTime = $this->makeFromSeconds($M * 60);

CamelCaseVariableName

Since: 0.2

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

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The method _registerDebugbar is not named in camelCase.
Open

    private function _registerDebugbar()
    {
        if (! $this->app->offsetExists('debugbar')) {
            return;
        }
Severity: Minor
Found in src/WidgetsServiceProvider.php by phpmd

CamelCaseMethodName

Since: 0.2

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

Example

class ClassName {
    public function get_name() {
    }
}

Source

Reduce the number of returns of this function 4, down to the maximum allowed 3.
Open

    private function determineDataMethod($widget): array

Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

Noncompliant Code Example

With the default threshold of 3:

function myFunction(){ // Noncompliant as there are 4 return statements
  if (condition1) {
    return true;
  } else {
    if (condition2) {
      return false;
    } else {
      return true;
    }
  }
  return false;
}

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

Severity
Category
Status
Source
Language