Skip to content

[12.x] Improve typing of arrays and callables #56470

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

Draft
wants to merge 25 commits into
base: 12.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1a5dba6
Type $handler callable in Connection::whenQueryingForLongerThan()
shaedrich Jul 27, 2025
60b5cf4
Properly type $queryDurationHandlers as list of a associative arrays
shaedrich Jul 28, 2025
db1ab6e
Type rest of the Connection class
shaedrich Jul 28, 2025
45a73d9
Improve typing of closure and array
shaedrich Jul 28, 2025
8274fdc
Narrow array down
shaedrich Jul 28, 2025
731719a
Merge branch 'laravel:12.x' into type-arrays-and-callables-properly
shaedrich Jul 28, 2025
333123f
Improve join callback typing
shaedrich Jul 28, 2025
83c84ff
Improve typing in Controller
shaedrich Jul 28, 2025
898d79d
Improve types for ControllerMiddlewareOptions
shaedrich Jul 28, 2025
1f59536
Improve callable and array typing for PendingRequest
shaedrich Jul 28, 2025
0f0ae3f
Add types to CacheManager
shaedrich Jul 28, 2025
3c74adf
Type $prefixed
shaedrich Jul 28, 2025
f994214
Type lottery in DatabaseLock class
shaedrich Jul 28, 2025
f49a3e0
Type arrays in MemcachedConnector
shaedrich Jul 28, 2025
ce5ebf7
Make weight option optional
shaedrich Jul 28, 2025
ad89ac1
make weight optional in MemcachedConnector server configuration
shaedrich Jul 28, 2025
d8f5208
Type callback of Localizable::withLocale() and note its return value …
shaedrich Jul 28, 2025
173d50f
Type Closure in PendingProcess
shaedrich Jul 28, 2025
ac92ef0
Typo
shaedrich Jul 29, 2025
0c4ae2e
Fix typo
shaedrich Jul 29, 2025
8e40407
Type $$currentCursorResolver Closure in AbstractCursorPaginator
shaedrich Jul 30, 2025
c8dce8a
Type closure in HidesAttributes.php
shaedrich Jul 30, 2025
ce89cb5
StyleCI
shaedrich Jul 30, 2025
fe59f95
Type connection Closure in ConnectionFactory
shaedrich Jul 30, 2025
862684f
Type Closure return value of ManagesFrequencies::inTimeInterval()
shaedrich Jul 30, 2025
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
23 changes: 12 additions & 11 deletions src/Illuminate/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function resolve($name)
/**
* Build a cache repository with the given configuration.
*
* @param array $config
* @param array{driver: string, name?: string} $config
* @return \Illuminate\Cache\Repository
*/
public function build(array $config)
Expand All @@ -137,7 +137,7 @@ public function build(array $config)
/**
* Call a custom driver creator.
*
* @param array $config
* @param array{driver: string} $config
* @return mixed
*/
protected function callCustomCreator(array $config)
Expand All @@ -161,7 +161,7 @@ protected function createApcDriver(array $config)
/**
* Create an instance of the array cache driver.
*
* @param array $config
* @param array{serialize?: bool} $config
* @return \Illuminate\Cache\Repository
*/
protected function createArrayDriver(array $config)
Expand All @@ -172,7 +172,7 @@ protected function createArrayDriver(array $config)
/**
* Create an instance of the file cache driver.
*
* @param array $config
* @param array{path: string, lock_path: string, permission?: int} $config
* @return \Illuminate\Cache\Repository
*/
protected function createFileDriver(array $config)
Expand All @@ -187,7 +187,7 @@ protected function createFileDriver(array $config)
/**
* Create an instance of the Memcached cache driver.
*
* @param array $config
* @param array{servers: array{host: string, port: int, weight?: int}[], persistent_id?: string|null, options?: array, sasl?: array{string, string}} $config
* @return \Illuminate\Cache\Repository
*/
protected function createMemcachedDriver(array $config)
Expand Down Expand Up @@ -217,7 +217,7 @@ protected function createNullDriver()
/**
* Create an instance of the Redis cache driver.
*
* @param array $config
* @param array{connection?: sttring, lock_connection?: string} $config
* @return \Illuminate\Cache\Repository
*/
protected function createRedisDriver(array $config)
Expand All @@ -237,7 +237,7 @@ protected function createRedisDriver(array $config)
/**
* Create an instance of the database cache driver.
*
* @param array $config
* @param array{table: string, connection?: string, lock_table?: string, lock_lottery?: array{int, int}, lock_timeout?: int, lock_connection?: string} $config
* @return \Illuminate\Cache\Repository
*/
protected function createDatabaseDriver(array $config)
Expand All @@ -264,7 +264,7 @@ protected function createDatabaseDriver(array $config)
/**
* Create an instance of the DynamoDB cache driver.
*
* @param array $config
* @param array{table: string, attributes?: array{key?: string, value?: string, expiration?: string}} $config
* @return \Illuminate\Cache\Repository
*/
protected function createDynamodbDriver(array $config)
Expand All @@ -287,6 +287,7 @@ protected function createDynamodbDriver(array $config)
/**
* Create new DynamoDb Client instance.
*
* @param array{region: string, endpoint?: string, key?: string, secret?: string, token?: string} $config
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types taken from \Aws\DynamoDb\DynamoDbClient

* @return \Aws\DynamoDb\DynamoDbClient
*/
protected function newDynamodbClient(array $config)
Expand Down Expand Up @@ -314,7 +315,7 @@ protected function newDynamodbClient(array $config)
* Create a new cache repository with the given implementation.
*
* @param \Illuminate\Contracts\Cache\Store $store
* @param array $config
* @param array{store?: string, events: bool} $config
* @return \Illuminate\Cache\Repository
*/
public function repository(Store $store, array $config = [])
Expand Down Expand Up @@ -356,7 +357,7 @@ public function refreshEventDispatcher()
/**
* Get the cache prefix.
*
* @param array $config
* @param array{prefix?: string} $config
* @return string
*/
protected function getPrefix(array $config)
Expand Down Expand Up @@ -403,7 +404,7 @@ public function setDefaultDriver($name)
/**
* Unset the given driver instances.
*
* @param array|string|null $name
* @param string[]|string|null $name
* @return $this
*/
public function forgetDriver($name = null)
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/DatabaseLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DatabaseLock extends Lock
/**
* The prune probability odds.
*
* @var array
* @var array{int, int}
*/
protected $lottery;

Expand All @@ -43,7 +43,7 @@ class DatabaseLock extends Lock
* @param string $name
* @param int $seconds
* @param string|null $owner
* @param array $lottery
* @param array{int, int} $lottery
* @param int $defaultTimeoutInSeconds
*/
public function __construct(Connection $connection, $table, $name, $seconds, $owner = null, $lottery = [2, 100], $defaultTimeoutInSeconds = 86400)
Expand Down
17 changes: 10 additions & 7 deletions src/Illuminate/Cache/DatabaseStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DatabaseStore implements LockProvider, Store
/**
* An array representation of the lock lottery odds.
*
* @var array
* @var array{int, int}
*/
protected $lockLottery;

Expand All @@ -75,7 +75,7 @@ class DatabaseStore implements LockProvider, Store
* @param string $table
* @param string $prefix
* @param string $lockTable
* @param array $lockLottery
* @param array{int, int} $lockLottery
* @param int $defaultLockTimeoutInSeconds
*/
public function __construct(
Expand Down Expand Up @@ -253,10 +253,13 @@ public function decrement($key, $value = 1)
/**
* Increment or decrement an item in the cache.
*
* @template TValue of int|float
* @template TReturn of int|false
*
* @param string $key
* @param int|float $value
* @param \Closure $callback
* @return int|false
* @param TValue $value
* @param (\Closure(int, TValue): TReturn) $callback
* @return TReturn
*/
protected function incrementOrDecrement($key, $value, Closure $callback)
{
Expand Down Expand Up @@ -377,7 +380,7 @@ public function forgetIfExpired($key)
/**
* Remove all items from the cache.
*
* @param array $keys
* @param array<int, string> $keys
* @return bool
*/
protected function forgetMany(array $keys)
Expand All @@ -393,7 +396,7 @@ protected function forgetMany(array $keys)
/**
* Remove all expired items from the given set from the cache.
*
* @param array $keys
* @param array<int, string> $keys
* @param bool $prefixed
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Cache/MemcachedConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class MemcachedConnector
/**
* Create a new Memcached connection.
*
* @param array $servers
* @param array{host: string, port: int, weight?: int}[] $servers
* @param string|null $connectionId
* @param array $options
* @param array $credentials
* @param array{string, string} $credentials
* @return \Memcached
*/
public function connect(array $servers, $connectionId = null, array $options = [], array $credentials = [])
Expand All @@ -39,7 +39,7 @@ public function connect(array $servers, $connectionId = null, array $options = [
* Get a new Memcached instance.
*
* @param string|null $connectionId
* @param array $credentials
* @param array{string, string} $credentials
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types taken from Memcached::setSaslAuthData()

* @param array $options
* @return \Memcached
*/
Expand Down Expand Up @@ -73,7 +73,7 @@ protected function createMemcachedInstance($connectionId)
* Set the SASL credentials on the Memcached connection.
*
* @param \Memcached $memcached
* @param array $credentials
* @param array{string, string} $credentials
* @return void
*/
protected function setCredentials($memcached, $credentials)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Scheduling/ManagesFrequencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function unlessBetween($startTime, $endTime)
*
* @param string $startTime
* @param string $endTime
* @return \Closure
* @return (\Closure(): bool)
*/
private function inTimeInterval($startTime, $endTime)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function createReadWriteConnection(array $config)
* Create a new PDO instance for reading.
*
* @param array $config
* @return \Closure
* @return (\Closure(array): \PDO)
*/
protected function createReadPdo(array $config)
{
Expand Down Expand Up @@ -157,7 +157,7 @@ protected function mergeReadWriteConfig(array $config, array $merge)
* Create a new Closure that resolves to a PDO instance.
*
* @param array $config
* @return \Closure
* @return (\Closure(array): \PDO)
*/
protected function createPdoResolver(array $config)
{
Expand All @@ -170,7 +170,7 @@ protected function createPdoResolver(array $config)
* Create a new Closure that resolves to a PDO instance with a specific host or an array of hosts.
*
* @param array $config
* @return \Closure
* @return (\Closure(array): \PDO)
*
* @throws \PDOException
*/
Expand Down Expand Up @@ -216,7 +216,7 @@ protected function parseHosts(array $config)
* Create a new Closure that resolves to a PDO instance where there is no configured host.
*
* @param array $config
* @return \Closure
* @return (\Closure(array): \PDO)
*/
protected function createPdoResolverWithoutHosts(array $config)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Concerns/HidesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function makeVisible($attributes)
/**
* Make the given, typically hidden, attributes visible if the given truth test passes.
*
* @param bool|\Closure $condition
* @param bool|(\Closure(\Illuminate\Database\Eloquent\Model): bool) $condition
* @param array<string>|string|null $attributes
* @return $this
*/
Expand All @@ -113,7 +113,7 @@ public function makeHidden($attributes)
/**
* Make the given, typically visible, attributes hidden if the given truth test passes.
*
* @param bool|\Closure $condition
* @param bool|(\Closure(\Illuminate\Database\Eloquent\Model): bool) $condition
* @param array<string>|string|null $attributes
* @return $this
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/JoinClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct(Builder $parentQuery, $type, $table)
*
* on `contacts`.`user_id` = `users`.`id` and `contacts`.`info_id` = `info`.`id`
*
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param (\Closure(\Illuminate\Database\Query\Builder): mixed)|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @param string $boolean
Expand All @@ -101,7 +101,7 @@ public function on($first, $operator = null, $second = null, $boolean = 'and')
/**
* Add an "or on" clause to the join.
*
* @param \Closure|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param (\Closure(\Illuminate\Database\Query\Builder): mixed)|\Illuminate\Contracts\Database\Query\Expression|string $first
* @param string|null $operator
* @param \Illuminate\Contracts\Database\Query\Expression|string|null $second
* @return \Illuminate\Database\Query\JoinClause
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public function retry(array|int $times, Closure|int $sleepMilliseconds = 0, ?cal
/**
* Replace the specified options on the request.
*
* @param array $options
* @param array<'cookies'|'form_params'|'headers'|'json'|'multipart'|'query', mixed> $options
* @return $this
*/
public function withOptions(array $options)
Expand Down Expand Up @@ -1312,7 +1312,7 @@ public function pushHandlers($handlerStack)
/**
* Build the before sending handler.
*
* @return \Closure
* @return (\Closure(callable): callable)
*/
public function buildBeforeSendingHandler()
{
Expand All @@ -1326,7 +1326,7 @@ public function buildBeforeSendingHandler()
/**
* Build the recorder handler.
*
* @return \Closure
* @return (\Closure(callable): callable)
*/
public function buildRecorderHandler()
{
Expand All @@ -1349,7 +1349,7 @@ public function buildRecorderHandler()
/**
* Build the stub handler.
*
* @return \Closure
* @return (\Closure(callable): callable)
*/
public function buildStubHandler()
{
Expand Down Expand Up @@ -1386,7 +1386,7 @@ public function buildStubHandler()
* Get the sink stub handler callback.
*
* @param string $sink
* @return \Closure
* @return (\Closure(\Illuminate\Http\Client\Response): void)
*/
protected function sinkStubHandler($sink)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Pagination/AbstractCursorPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ abstract class AbstractCursorPaginator implements Htmlable, Stringable
/**
* The current cursor resolver callback.
*
* @var \Closure
* @var (\Closure(string): \Illuminate\Pagination\Cursor|null)
*/
protected static $currentCursorResolver;

Expand Down Expand Up @@ -512,7 +512,7 @@ public static function resolveCurrentCursor($cursorName = 'cursor', $default = n
/**
* Set the current cursor resolver callback.
*
* @param \Closure $resolver
* @param (\Closure(string): \Illuminate\Pagination\Cursor|null) $resolver
* @return void
*/
public static function currentCursorResolver(Closure $resolver)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Pipeline/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected function carry()
* Parse full pipe string to get name and parameters.
*
* @param string $pipe
* @return array
* @return array<string|null, string[]>
*/
protected function parsePipeString($pipe)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Process/PendingProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ protected function fakeFor(string $command)
* Resolve the given fake handler for a synchronous process.
*
* @param string $command
* @param \Closure $fake
* @return mixed
* @param (\Closure(\Illuminate\Process\PendingProcess): int|string|array|\Illuminate\Process\ProcessResult|\Illuminate\Process\FakeProcessResult|\Illuminate\Process\FakeProcessDescription|\Illuminate\Process\FakeProcessSequence|\Throwable) $fake
* @return \Illuminate\Process\FakeProcessResult|\Illuminate\Contracts\Process\ProcessResult|\Illuminate\Process\FakeProcessDescription|mixed
*/
protected function resolveSynchronousFake(string $command, Closure $fake)
{
Expand Down Expand Up @@ -396,7 +396,7 @@ protected function resolveSynchronousFake(string $command, Closure $fake)
*
* @param string $command
* @param callable|null $output
* @param \Closure $fake
* @param (\Closure(\Illuminate\Process\PendingProcess): int|string|array|\Illuminate\Process\ProcessResult|\Illuminate\Process\FakeProcessResult|\Illuminate\Process\FakeProcessDescription|\Illuminate\Process\FakeProcessSequence|\Throwable) $fake
* @return \Illuminate\Process\FakeInvokedProcess
*
* @throws \LogicException
Expand Down
Loading