takeawaytown/laravel-uuid

View on GitHub
src/Traits/Uuid.php

Summary

Maintainability
A
0 mins
Test Coverage

The method scopeUuid has a boolean flag argument $first, which is a certain sign of a Single Responsibility Principle violation.
Open

  public function scopeUuid($query, $uuid, $first = true)
Severity: Minor
Found in src/Traits/Uuid.php by phpmd

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

Define a constant instead of duplicating this literal "uuid.uuid_column" 6 times.
Open

      if (!$model->{config('uuid.uuid_column')}) {
Severity: Critical
Found in src/Traits/Uuid.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Call to undeclared function \config()
Open

      $uuid = $model->getOriginal(config('uuid.uuid_column'));
Severity: Critical
Found in src/Traits/Uuid.php by phan

Call to method __construct from undeclared class \Illuminate\Database\Eloquent\ModelNotFoundException
Open

      throw (new ModelNotFoundException)->setModel(get_class($this));
Severity: Critical
Found in src/Traits/Uuid.php by phan

Call to method setModel from undeclared class \Illuminate\Database\Eloquent\ModelNotFoundException
Open

      throw (new ModelNotFoundException)->setModel(get_class($this));
Severity: Critical
Found in src/Traits/Uuid.php by phan

Static call to undeclared method \TakeawayTown\LaravelUuid\Classes\Uuid,1::saving
Open

    static::saving(function ($model) {
Severity: Critical
Found in src/Traits/Uuid.php by phan

Call to undeclared function \config()
Open

      if (!$model->{config('uuid.uuid_column')}) {
Severity: Critical
Found in src/Traits/Uuid.php by phan

Reference to parent from trait \TakeawayTown\LaravelUuid\Classes\Uuid,1
Open

    parent::boot();
Severity: Info
Found in src/Traits/Uuid.php by phan

Call to method where on non-class type string
Open

    $results = $query->where(config('uuid.uuid_column'), $uuid);
Severity: Critical
Found in src/Traits/Uuid.php by phan

Trait \TakeawayTown\LaravelUuid\Classes\Uuid defined at /code/src/Traits/Uuid.php:8 was previously defined as Class \TakeawayTown\LaravelUuid\Classes\Uuid at /code/src/Classes/Uuid.php:13
Open

trait Uuid
Severity: Minor
Found in src/Traits/Uuid.php by phan

Call to undeclared function \config()
Open

        $model->{config('uuid.uuid_column')} = strtoupper(Uuid::generate()->string);
Severity: Critical
Found in src/Traits/Uuid.php by phan

Call to undeclared function \config()
Open

      if ($uuid !== $model->{config('uuid.uuid_column')}) {
Severity: Critical
Found in src/Traits/Uuid.php by phan

Saw possibly unextractable annotation for a fragment of comment '* @param string uuid of the model.': after string, did not see an element name (will guess based on comment order)
Open

   * @param  string  uuid of the model.
Severity: Info
Found in src/Traits/Uuid.php by phan

Static call to undeclared method \TakeawayTown\LaravelUuid\Classes\Uuid,1::creating
Open

    static::creating(function ($model) {
Severity: Critical
Found in src/Traits/Uuid.php by phan

Call to undeclared function \config()
Open

        $model->{config('uuid.uuid_column')} = $uuid;
Severity: Critical
Found in src/Traits/Uuid.php by phan

Call to undeclared function \config()
Open

    $results = $query->where(config('uuid.uuid_column'), $uuid);
Severity: Critical
Found in src/Traits/Uuid.php by phan

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

    static::creating(function ($model) {
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

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

        $model->{config('uuid.uuid_column')} = strtoupper(Uuid::generate()->string);
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Expected 1 space after closing parenthesis; found 5
Open

    if (!is_string($uuid) || $match !== 1)
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 12 spaces, found 6
Open

      }
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected at least 12 spaces, found 6
Open

      $uuid = $model->getOriginal(config('uuid.uuid_column'));
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 12 spaces, found 6
Open

      if ($uuid !== $model->{config('uuid.uuid_column')}) {
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 4 spaces, found 2
Open

  }
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 8 spaces, found 4
Open

    });
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

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

    parent::boot();
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

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

    return $first ? $results->firstOrFail() : $results;
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

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

    static::saving(function ($model) {
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

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

        $model->{config('uuid.uuid_column')} = $uuid;
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

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

    {
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 8 spaces, found 4
Open

    });
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

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

    $match = preg_match(Uuid::REGEX, $uuid);
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 4 spaces, found 2
Open

  protected static function boot()
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 8 spaces, found 4
Open

    if (!is_string($uuid) || $match !== 1)
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected at least 4 spaces, found 2
Open

  {
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 8 spaces, found 4
Open

    }
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 12 spaces, found 6
Open

      }
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 4 spaces, found 2
Open

  public function scopeUuid($query, $uuid, $first = true)
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected at least 12 spaces, found 6
Open

      throw (new ModelNotFoundException)->setModel(get_class($this));
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

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

    $results = $query->where(config('uuid.uuid_column'), $uuid);
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected at least 4 spaces, found 2
Open

  {
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 4 spaces, found 2
Open

  }
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

Line indented incorrectly; expected 12 spaces, found 6
Open

      if (!$model->{config('uuid.uuid_column')}) {
Severity: Minor
Found in src/Traits/Uuid.php by phpcodesniffer

There are no issues that match your filters.

Category
Status