| Conditions | 5 |
| Paths | 1 |
| Total Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 31 | protected static function bootUsesUuidAsPrimary(): void |
||
| 32 | { |
||
| 33 | static::creating(static function (UuidAsPrimaryContract $model): void { |
||
| 34 | $keyName = $model->getKeyName(); |
||
| 35 | |||
| 36 | if (! empty($model->{$keyName})) { |
||
| 37 | // Do some validation |
||
| 38 | $model->isUuidBinary($model->{$keyName}) |
||
| 39 | ? Uuid::fromBytes($model->{$keyName}) |
||
| 40 | : Uuid::fromString($model->{$keyName}); |
||
| 41 | } elseif (! empty($model->attributes[$keyName])) { |
||
|
|
|||
| 42 | // Do some validation |
||
| 43 | $model->isUuidBinary($model->attributes[$keyName]) |
||
| 44 | ? Uuid::fromBytes($model->attributes[$keyName]) |
||
| 45 | : Uuid::fromString($model->attributes[$keyName]); |
||
| 46 | } else { |
||
| 47 | $model->{$keyName} = Uuid::uuid1()->getBytes(); |
||
| 48 | } |
||
| 49 | }); |
||
| 50 | } |
||
| 51 | } |
||
| 52 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: