Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tap fluent chainable #53753

Draft
wants to merge 8 commits into
base: 11.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
First hundred-ish files
  • Loading branch information
shaedrich authored Dec 3, 2024
commit cefac84b0c20327ff93b15de5728fb1a97b23dae
8 changes: 2 additions & 6 deletions src/Illuminate/Auth/Access/AuthorizationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public function response()
*/
public function setResponse($response)
{
$this->response = $response;

return $this;
return tap($this, fn () => $this->response = $response);
}

/**
Expand All @@ -67,9 +65,7 @@ public function setResponse($response)
*/
public function withStatus($status)
{
$this->status = $status;

return $this;
return tap($this, fn () => $this->status = $status);
}

/**
Expand Down
24 changes: 6 additions & 18 deletions src/Illuminate/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ protected function buildAbilityCallback($ability, $callback)
*/
public function policy($class, $policy)
{
$this->policies[$class] = $policy;

return $this;
return tap($this, fn () => $this->policies[$class] = $policy);
}

/**
Expand All @@ -304,9 +302,7 @@ public function policy($class, $policy)
*/
public function before(callable $callback)
{
$this->beforeCallbacks[] = $callback;

return $this;
return tap($this, fn () => $this->beforeCallbacks[] = $callback);
}

/**
Expand All @@ -317,9 +313,7 @@ public function before(callable $callback)
*/
public function after(callable $callback)
{
$this->afterCallbacks[] = $callback;

return $this;
return tap($this, fn () => $this->afterCallbacks[] = $callback);
}

/**
Expand Down Expand Up @@ -716,9 +710,7 @@ protected function guessPolicyName($class)
*/
public function guessPolicyNamesUsing(callable $callback)
{
$this->guessPolicyNamesUsingCallback = $callback;

return $this;
return tap($this, fn () => $this->guessPolicyNamesUsingCallback = $callback);
}

/**
Expand Down Expand Up @@ -883,9 +875,7 @@ public function policies()
*/
public function defaultDenialResponse(Response $response)
{
$this->defaultDenialResponse = $response;

return $this;
return tap($this, fn () => $this->defaultDenialResponse = $response);
}

/**
Expand All @@ -896,8 +886,6 @@ public function defaultDenialResponse(Response $response)
*/
public function setContainer(Container $container)
{
$this->container = $container;

return $this;
return tap($this, fn () => $this->container = $container);
}
}
4 changes: 1 addition & 3 deletions src/Illuminate/Auth/Access/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ public function authorize()
*/
public function withStatus($status)
{
$this->status = $status;

return $this;
return tap($this, fn () => $this->status = $status);
}

/**
Expand Down
20 changes: 5 additions & 15 deletions src/Illuminate/Auth/AuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ public function userResolver()
*/
public function resolveUsersUsing(Closure $userResolver)
{
$this->userResolver = $userResolver;

return $this;
return tap($this, fn () => $this->userResolver = $userResolver);
}

/**
Expand All @@ -275,9 +273,7 @@ public function resolveUsersUsing(Closure $userResolver)
*/
public function extend($driver, Closure $callback)
{
$this->customCreators[$driver] = $callback;

return $this;
return tap($this, fn () => $this->customCreators[$driver] = $callback);
}

/**
Expand All @@ -289,9 +285,7 @@ public function extend($driver, Closure $callback)
*/
public function provider($name, Closure $callback)
{
$this->customProviderCreators[$name] = $callback;

return $this;
return tap($this, fn () => $this->customProviderCreators[$name] = $callback);
}

/**
Expand All @@ -311,9 +305,7 @@ public function hasResolvedGuards()
*/
public function forgetGuards()
{
$this->guards = [];

return $this;
return tap($this, fn() => $this->guards = []);
}

/**
Expand All @@ -324,9 +316,7 @@ public function forgetGuards()
*/
public function setApplication($app)
{
$this->app = $app;

return $this;
return tap($this, fn() => $this->app = $app);
}

/**
Expand Down
12 changes: 3 additions & 9 deletions src/Illuminate/Auth/EloquentUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ public function getHasher()
*/
public function setHasher(HasherContract $hasher)
{
$this->hasher = $hasher;

return $this;
return tap($this, fn () => $this->hasher = $hasher);
}

/**
Expand All @@ -250,9 +248,7 @@ public function getModel()
*/
public function setModel($model)
{
$this->model = $model;

return $this;
return tap($this, fn () => $this->model = $model);
}

/**
Expand All @@ -273,8 +269,6 @@ public function getQueryCallback()
*/
public function withQuery($queryCallback = null)
{
$this->queryCallback = $queryCallback;

return $this;
return tap($this, fn () => $this->queryCallback = $queryCallback);
}
}
8 changes: 2 additions & 6 deletions src/Illuminate/Auth/GuardHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ public function id()
*/
public function setUser(AuthenticatableContract $user)
{
$this->user = $user;

return $this;
return tap($this, fn () => $this->user = $user);
}

/**
Expand All @@ -98,9 +96,7 @@ public function setUser(AuthenticatableContract $user)
*/
public function forgetUser()
{
$this->user = null;

return $this;
return tap($this, fn () => $this->user = null);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Auth/RequestGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public function validate(#[\SensitiveParameter] array $credentials = [])
*/
public function setRequest(Request $request)
{
$this->request = $request;

return $this;
return tap($this, fn () => $this->request = $request);
}
}
8 changes: 2 additions & 6 deletions src/Illuminate/Auth/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,7 @@ protected function getRememberDuration()
*/
public function setRememberDuration($minutes)
{
$this->rememberDuration = $minutes;

return $this;
return tap($this, fn () => $this->rememberDuration = $minutes);
}

/**
Expand Down Expand Up @@ -972,9 +970,7 @@ public function getRequest()
*/
public function setRequest(Request $request)
{
$this->request = $request;

return $this;
return tap($this, fn () => $this->request = $request);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Auth/TokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ public function validate(array $credentials = [])
*/
public function setRequest(Request $request)
{
$this->request = $request;

return $this;
return tap($this, fn () => $this->request = $request);
}
}
12 changes: 3 additions & 9 deletions src/Illuminate/Broadcasting/AnonymousEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ public function __construct(protected Channel|array|string $channels)
*/
public function via(string $connection): static
{
$this->connection = $connection;

return $this;
return tap($this, fn () => $this->connection = $connection);
}

/**
* Set the name the event should be broadcast as.
*/
public function as(string $name): static
{
$this->name = $name;

return $this;
return tap($this, fn () => $this->name = $name);
}

/**
Expand All @@ -86,9 +82,7 @@ public function with(Arrayable|array $payload): static
*/
public function toOthers(): static
{
$this->includeCurrentUser = false;

return $this;
return tap($this, fn () => $this->includeCurrentUser = false);
}

/**
Expand Down
12 changes: 3 additions & 9 deletions src/Illuminate/Broadcasting/BroadcastManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,7 @@ public function purge($name = null)
*/
public function extend($driver, Closure $callback)
{
$this->customCreators[$driver] = $callback;

return $this;
return tap($this, fn () => $this->customCreators[$driver] = $callback);
}

/**
Expand All @@ -494,9 +492,7 @@ public function getApplication()
*/
public function setApplication($app)
{
$this->app = $app;

return $this;
return tap($this, fn () => $this->app = $app);
}

/**
Expand All @@ -506,9 +502,7 @@ public function setApplication($app)
*/
public function forgetDrivers()
{
$this->drivers = [];

return $this;
return tap($this, fn () => $this->drivers = []);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Illuminate/Broadcasting/InteractsWithSockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ trait InteractsWithSockets
*/
public function dontBroadcastToCurrentUser()
{
$this->socket = Broadcast::socket();

return $this;
return tap($this, fn () => $this->socket = Broadcast::socket());
}

/**
Expand All @@ -32,8 +30,6 @@ public function dontBroadcastToCurrentUser()
*/
public function broadcastToEveryone()
{
$this->socket = null;

return $this;
return tap($this, fn () => $this->socket = null);
}
}
4 changes: 1 addition & 3 deletions src/Illuminate/Bus/Batchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public function batching()
*/
public function withBatchId(string $batchId)
{
$this->batchId = $batchId;

return $this;
return tap($this, fn () => $this->batchId = $batchId);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Illuminate/Bus/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ public function dispatchAfterResponse($command, $handler = null)
*/
public function pipeThrough(array $pipes)
{
$this->pipes = $pipes;

return $this;
return tap($this, fn () => $this->pipes = $pipes);
}

/**
Expand All @@ -279,8 +277,6 @@ public function pipeThrough(array $pipes)
*/
public function map(array $map)
{
$this->handlers = array_merge($this->handlers, $map);

return $this;
return tap($this, fn () => $this->handlers = array_merge($this->handlers, $map));
}
}
Loading