src/Traits/Uuid.php
The method scopeUuid has a boolean flag argument $first, which is a certain sign of a Single Responsibility Principle violation. Open
Open
public function scopeUuid($query, $uuid, $first = true)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
Open
if (!$model->{config('uuid.uuid_column')}) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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
Open
$uuid = $model->getOriginal(config('uuid.uuid_column'));
- Create a ticketCreate a ticket
- Exclude checks
Call to method __construct
from undeclared class \Illuminate\Database\Eloquent\ModelNotFoundException
Open
Open
throw (new ModelNotFoundException)->setModel(get_class($this));
- Create a ticketCreate a ticket
- Exclude checks
Call to method setModel
from undeclared class \Illuminate\Database\Eloquent\ModelNotFoundException
Open
Open
throw (new ModelNotFoundException)->setModel(get_class($this));
- Create a ticketCreate a ticket
- Exclude checks
Static call to undeclared method \TakeawayTown\LaravelUuid\Classes\Uuid,1::saving
Open
Open
static::saving(function ($model) {
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \config()
Open
Open
if (!$model->{config('uuid.uuid_column')}) {
- Create a ticketCreate a ticket
- Exclude checks
Reference to parent from trait \TakeawayTown\LaravelUuid\Classes\Uuid,1
Open
Open
parent::boot();
- Create a ticketCreate a ticket
- Exclude checks
Call to method where
on non-class type string
Open
Open
$results = $query->where(config('uuid.uuid_column'), $uuid);
- Create a ticketCreate a ticket
- Exclude checks
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
Open
trait Uuid
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \config()
Open
Open
$model->{config('uuid.uuid_column')} = strtoupper(Uuid::generate()->string);
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \config()
Open
Open
if ($uuid !== $model->{config('uuid.uuid_column')}) {
- Create a ticketCreate a ticket
- Exclude checks
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
Open
* @param string uuid of the model.
- Create a ticketCreate a ticket
- Exclude checks
Static call to undeclared method \TakeawayTown\LaravelUuid\Classes\Uuid,1::creating
Open
Open
static::creating(function ($model) {
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \config()
Open
Open
$model->{config('uuid.uuid_column')} = $uuid;
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \config()
Open
Open
$results = $query->where(config('uuid.uuid_column'), $uuid);
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
static::creating(function ($model) {
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 8 Open
Open
$model->{config('uuid.uuid_column')} = strtoupper(Uuid::generate()->string);
- Create a ticketCreate a ticket
- Exclude checks
Expected 1 space after closing parenthesis; found 5 Open
Open
if (!is_string($uuid) || $match !== 1)
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
Open
}
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
Open
$uuid = $model->getOriginal(config('uuid.uuid_column'));
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
Open
if ($uuid !== $model->{config('uuid.uuid_column')}) {
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
}
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
});
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
parent::boot();
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
return $first ? $results->firstOrFail() : $results;
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
static::saving(function ($model) {
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 8 Open
Open
$model->{config('uuid.uuid_column')} = $uuid;
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
{
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
});
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
$match = preg_match(Uuid::REGEX, $uuid);
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
protected static function boot()
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
if (!is_string($uuid) || $match !== 1)
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
Open
{
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
Open
}
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
Open
}
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
public function scopeUuid($query, $uuid, $first = true)
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
Open
throw (new ModelNotFoundException)->setModel(get_class($this));
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
Open
$results = $query->where(config('uuid.uuid_column'), $uuid);
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
Open
{
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
Open
}
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 6 Open
Open
if (!$model->{config('uuid.uuid_column')}) {
- Create a ticketCreate a ticket
- Exclude checks