UniSharp /
laravel-uploadable
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 2 | |||
|
0 ignored issues
–
show
|
|||
| 3 | namespace UniSharp\Uploadable; |
||
| 4 | |||
| 5 | use Illuminate\Support\Facades\URL; |
||
| 6 | use Illuminate\Database\Eloquent\Model; |
||
| 7 | use Illuminate\Support\Facades\Storage; |
||
| 8 | use Illuminate\Database\Eloquent\Relations\MorphTo; |
||
| 9 | |||
| 10 | class File extends Model |
||
|
0 ignored issues
–
show
|
|||
| 11 | { |
||
|
0 ignored issues
–
show
|
|||
| 12 | protected $fillable = ['name', 'mime', 'size', 'path', 'extra']; |
||
|
0 ignored issues
–
show
|
|||
| 13 | |||
| 14 | 8 | public static function boot(): void |
|
|
0 ignored issues
–
show
|
|||
| 15 | { |
||
|
0 ignored issues
–
show
|
|||
| 16 | 4 | parent::boot(); |
|
| 17 | |||
| 18 | 8 | static::deleted(function ($model) { |
|
|
0 ignored issues
–
show
|
|||
| 19 | 4 | Storage::delete($model->attributes['path']); |
|
| 20 | 8 | }); |
|
|
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
Loading history...
|
|||
| 21 | 4 | } |
|
|
0 ignored issues
–
show
|
|||
| 22 | |||
| 23 | 20 | public function uploadable(): MorphTo |
|
|
0 ignored issues
–
show
|
|||
| 24 | { |
||
|
0 ignored issues
–
show
|
|||
| 25 | 20 | return $this->morphTo(); |
|
| 26 | } |
||
|
0 ignored issues
–
show
|
|||
| 27 | |||
| 28 | 2 | public function getPathAttribute(): ?string |
|
|
0 ignored issues
–
show
|
|||
| 29 | { |
||
|
0 ignored issues
–
show
|
|||
| 30 | 2 | if (!array_key_exists('path', $this->attributes)) { |
|
|
0 ignored issues
–
show
|
|||
| 31 | return null; |
||
|
0 ignored issues
–
show
|
|||
| 32 | } |
||
| 33 | |||
| 34 | 2 | return URL::to($this->attributes['path']); |
|
| 35 | } |
||
|
0 ignored issues
–
show
|
|||
| 36 | } |
||
|
0 ignored issues
–
show
|
|||
| 37 |