LoginSignup
4
0

More than 1 year has passed since last update.

Laravelのリファクタリング例

Posted at

throw_if

before

if ($boolean) {
    throw new CustomException();
}

after

throw_if ($boolean, CustomException::class);

abort_if

before

if ($boolean) {
    abort(403);
}

after

abort_if ($boolean, 403);

@continue

@foreach ($results as $result)
    @if ($result->type === 1)
        @continue 
    @endif
    ...
@endforeach

after

@foreach ($results as $result)
    @continue  ($result->type === 1)
    ...
@endforeach

@break

@foreach ($results as $result)
    @if ($result->status === 1)
        @break 
    @endif
    ...
@endforeach

after

@foreach ($results as $result)
    @break  ($result->status === 1)
    ...
@endforeach

includeWhen

if ($boolean) {
    include('view.name')
}

after

includeWhen($boolean, 'view.name');
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0