Skip to content

Commit 582955c

Browse files
authored
[11.x] chore: update to PHPStan Level 1 (#51956)
* chore: update to phpstan level 1 * chore: update facades to use @mixin * fix: HasAttributes::relationsToArray isset logic
1 parent cac7d24 commit 582955c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+135
-104
lines changed

phpstan.src.neon.dist

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
parameters:
2-
level: 0
2+
level: 1
33
paths:
44
- src
55
excludePaths:
66
- src/Illuminate/Testing/ParallelRunner.php
7+
- src/*/views/*
78
ignoreErrors:
89
- "#\\(void\\) is used#"
910
- "#Access to an undefined property#"

src/Illuminate/Auth/Access/Gate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ protected function callBeforeCallbacks($user, $ability, array $arguments)
575575
* @param \Illuminate\Contracts\Auth\Authenticatable $user
576576
* @param string $ability
577577
* @param array $arguments
578-
* @param bool $result
578+
* @param bool|null $result
579579
* @return bool|null
580580
*/
581581
protected function callAfterCallbacks($user, $ability, array $arguments, $result)

src/Illuminate/Bus/PendingBatch.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ protected function dispatchExistingBatch($batch)
358358
try {
359359
$batch = $batch->add($this->jobs);
360360
} catch (Throwable $e) {
361-
if (isset($batch)) {
362-
$batch->delete();
363-
}
361+
$batch->delete();
364362

365363
throw $e;
366364
}

src/Illuminate/Cache/RetrievesMultipleKeys.php

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function many(array $keys)
2121
})->all();
2222

2323
foreach ($keys as $key => $default) {
24+
/** @phpstan-ignore arguments.count (some clients don't accept a default) */
2425
$return[$key] = $this->get($key, $default);
2526
}
2627

src/Illuminate/Collections/Collection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ public function hasAny($key)
604604
/**
605605
* Concatenate values of a given key as a string.
606606
*
607-
* @param callable|string $value
607+
* @param callable|string|null $value
608608
* @param string|null $glue
609609
* @return string
610610
*/

src/Illuminate/Database/Connectors/ConnectionFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ protected function createPdoResolverWithHosts(array $config)
188188
}
189189
}
190190

191-
throw $e;
191+
if (isset($e)) {
192+
throw $e;
193+
}
192194
};
193195
}
194196

src/Illuminate/Database/Connectors/MySqlConnector.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ protected function getSocketDsn(array $config)
7777
*/
7878
protected function getHostDsn(array $config)
7979
{
80-
extract($config, EXTR_SKIP);
81-
82-
return isset($port)
83-
? "mysql:host={$host};port={$port};dbname={$database}"
84-
: "mysql:host={$host};dbname={$database}";
80+
return isset($config['port'])
81+
? "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}"
82+
: "mysql:host={$config['host']};dbname={$config['database']}";
8583
}
8684

8785
/**

src/Illuminate/Database/Connectors/PostgresConnector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected function getDsn(array $config)
127127
// Sometimes - users may need to connect to a database that has a different
128128
// name than the database used for "information_schema" queries. This is
129129
// typically the case if using "pgbouncer" type software when pooling.
130-
$database = $connect_via_database ?? $database;
130+
$database = $connect_via_database ?? $database ?? null;
131131
$port = $connect_via_port ?? $port ?? null;
132132

133133
$dsn = "pgsql:{$host}dbname='{$database}'";

src/Illuminate/Database/Console/DatabaseInspectionCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function getConnectionCount(ConnectionInterface $connection)
5858
/**
5959
* Get the connection configuration details for the given connection.
6060
*
61-
* @param string $database
61+
* @param string|null $database
6262
* @return array
6363
*/
6464
protected function getConfigFromDatabase($database)

src/Illuminate/Database/Eloquent/Attributes/ObservedBy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ObservedBy
1313
* @param array|string $classes
1414
* @return void
1515
*/
16-
public function __construct(array|string $classes)
16+
public function __construct(public array|string $classes)
1717
{
1818
}
1919
}

src/Illuminate/Database/Eloquent/Attributes/ScopedBy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ScopedBy
1313
* @param array|string $classes
1414
* @return void
1515
*/
16-
public function __construct(array|string $classes)
16+
public function __construct(public array|string $classes)
1717
{
1818
}
1919
}

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ public function relationsToArray()
394394
// If the relation value has been set, we will set it on this attributes
395395
// list for returning. If it was not arrayable or null, we'll not set
396396
// the value on the array because it is some type of invalid value.
397-
if (isset($relation) || is_null($value)) {
398-
$attributes[$key] = $relation;
397+
if (array_key_exists('relation', get_defined_vars())) { // check if $relation is in scope (could be null)
398+
$attributes[$key] = $relation ?? null;
399399
}
400400

401401
unset($relation);
@@ -1208,7 +1208,7 @@ protected function setClassCastableAttribute($key, $value)
12081208
* Set the value of an enum castable attribute.
12091209
*
12101210
* @param string $key
1211-
* @param \UnitEnum|string|int $value
1211+
* @param \UnitEnum|string|int|null $value
12121212
* @return void
12131213
*/
12141214
protected function setEnumCastableAttribute($key, $value)
@@ -1326,7 +1326,7 @@ protected function asJson($value)
13261326
/**
13271327
* Decode the given JSON back into an array or object.
13281328
*
1329-
* @param string $value
1329+
* @param string|null $value
13301330
* @param bool $asObject
13311331
* @return mixed
13321332
*/

src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ protected function morphEagerTo($name, $type, $id, $ownerKey)
329329
* @param string $name
330330
* @param string $type
331331
* @param string $id
332-
* @param string $ownerKey
332+
* @param string|null $ownerKey
333333
* @return \Illuminate\Database\Eloquent\Relations\MorphTo<\Illuminate\Database\Eloquent\Model, $this>
334334
*/
335335
protected function morphInstanceTo($target, $name, $type, $id, $ownerKey)

src/Illuminate/Database/Eloquent/Relations/Concerns/CanBeOneOfMany.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ protected function newOneOfManySubQuery($groupBy, $columns = null, $aggregate =
214214
}
215215
}
216216

217-
$this->addOneOfManySubQueryConstraints($subQuery, $groupBy, $columns, $aggregate);
217+
$this->addOneOfManySubQueryConstraints($subQuery, column: null, aggregate: $aggregate);
218218

219219
return $subQuery;
220220
}
@@ -237,7 +237,7 @@ protected function addOneOfManyJoinSubQuery(Builder $parent, Builder $subQuery,
237237
$join->on($this->qualifySubSelectColumn($onColumn.'_aggregate'), '=', $this->qualifyRelatedColumn($onColumn));
238238
}
239239

240-
$this->addOneOfManyJoinSubQueryConstraints($join, $on);
240+
$this->addOneOfManyJoinSubQueryConstraints($join);
241241
});
242242
});
243243
}

src/Illuminate/Database/Query/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Builder implements BuilderContract
163163
/**
164164
* The number of records to skip.
165165
*
166-
* @var int
166+
* @var int|null
167167
*/
168168
public $offset;
169169

src/Illuminate/Database/Schema/Builder.php

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public function hasTable($table)
144144
{
145145
$table = $this->connection->getTablePrefix().$table;
146146

147+
/** @phpstan-ignore arguments.count (SQLite accepts a withSize argument) */
147148
foreach ($this->getTables(false) as $value) {
148149
if (strtolower($table) === strtolower($value['name'])) {
149150
return true;

src/Illuminate/Database/Schema/Grammars/Grammar.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,12 @@ public function wrapTable($table)
332332
* Wrap a value in keyword identifiers.
333333
*
334334
* @param \Illuminate\Support\Fluent|\Illuminate\Contracts\Database\Query\Expression|string $value
335-
* @param bool $prefixAlias
336335
* @return string
337336
*/
338-
public function wrap($value, $prefixAlias = false)
337+
public function wrap($value)
339338
{
340339
return parent::wrap(
341-
$value instanceof Fluent ? $value->name : $value, $prefixAlias
340+
$value instanceof Fluent ? $value->name : $value,
342341
);
343342
}
344343

src/Illuminate/Foundation/Console/DownCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected function getDownFilePayload()
8787
'retry' => $this->getRetryTime(),
8888
'refresh' => $this->option('refresh'),
8989
'secret' => $this->getSecret(),
90-
'status' => (int) $this->option('status', 503),
90+
'status' => (int) ($this->option('status') ?? 503),
9191
'template' => $this->option('render') ? $this->prerenderView() : null,
9292
];
9393
}

src/Illuminate/Foundation/stubs/facade.stub

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace DummyNamespace;
55
use Illuminate\Support\Facades\Facade;
66

77
/**
8-
* @see \DummyTarget
8+
* @mixin \DummyTarget
99
*/
1010
class DummyClass extends Facade
1111
{

src/Illuminate/Hashing/HashManager.php

+10
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,14 @@ public function getDefaultDriver()
108108
{
109109
return $this->config->get('hashing.driver', 'bcrypt');
110110
}
111+
112+
/**
113+
* Verifies that the configuration is less than or equal to what is configured.
114+
*
115+
* @internal
116+
*/
117+
public function verifyConfiguration($value)
118+
{
119+
return $this->driver()->verifyConfiguration($value);
120+
}
111121
}

src/Illuminate/Http/UploadedFile.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function storePublicly($path = '', $options = [])
5656
* Store the uploaded file on a filesystem disk with public visibility.
5757
*
5858
* @param string $path
59-
* @param string $name
59+
* @param array|string|null $name
6060
* @param array|string $options
6161
* @return string|false
6262
*/

src/Illuminate/Mail/Mailer.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ protected function parseView($view)
408408
* Add the content to a given message.
409409
*
410410
* @param \Illuminate\Mail\Message $message
411-
* @param string $view
412-
* @param string $plain
413-
* @param string $raw
411+
* @param string|null $view
412+
* @param string|null $plain
413+
* @param string|null $raw
414414
* @param array $data
415415
* @return void
416416
*/

src/Illuminate/Notifications/Messages/SimpleMessage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function with($line)
226226
/**
227227
* Format the given line of text.
228228
*
229-
* @param \Illuminate\Contracts\Support\Htmlable|string|array $line
229+
* @param \Illuminate\Contracts\Support\Htmlable|string|array|null $line
230230
* @return \Illuminate\Contracts\Support\Htmlable|string
231231
*/
232232
protected function formatLine($line)

src/Illuminate/Routing/Middleware/SubstituteBindings.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ public function __construct(Registrar $router)
3535
*/
3636
public function handle($request, Closure $next)
3737
{
38-
try {
39-
$this->router->substituteBindings($route = $request->route());
38+
$route = $request->route();
4039

40+
try {
41+
$this->router->substituteBindings($route);
4142
$this->router->substituteImplicitBindings($route);
4243
} catch (ModelNotFoundException $exception) {
4344
if ($route->getMissing()) {

src/Illuminate/Routing/Route.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ public function getPrefix()
796796
/**
797797
* Add a prefix to the route URI.
798798
*
799-
* @param string $prefix
799+
* @param string|null $prefix
800800
* @return $this
801801
*/
802802
public function prefix($prefix)

src/Illuminate/Routing/RouteCollection.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ public function add(Route $route)
5959
*/
6060
protected function addToCollections($route)
6161
{
62+
$methods = $route->methods();
6263
$domainAndUri = $route->getDomain().$route->uri();
6364

64-
foreach ($route->methods() as $method) {
65+
foreach ($methods as $method) {
6566
$this->routes[$method][$domainAndUri] = $route;
6667
}
6768

68-
$this->allRoutes[$method.$domainAndUri] = $route;
69+
$this->allRoutes[implode('|', $methods).$domainAndUri] = $route;
6970
}
7071

7172
/**

src/Illuminate/Support/Facades/App.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
* @method static bool hasMacro(string $name)
141141
* @method static void flushMacros()
142142
*
143-
* @see \Illuminate\Foundation\Application
143+
* @mixin \Illuminate\Foundation\Application
144144
*/
145145
class App extends Facade
146146
{

src/Illuminate/Support/Facades/Artisan.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @method static \Illuminate\Foundation\Console\Kernel addCommandPaths(array $paths)
2424
* @method static \Illuminate\Foundation\Console\Kernel addCommandRoutePaths(array $paths)
2525
*
26-
* @see \Illuminate\Foundation\Console\Kernel
26+
* @mixin \Illuminate\Foundation\Console\Kernel
2727
*/
2828
class Artisan extends Facade
2929
{

src/Illuminate/Support/Facades/Auth.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
* @method static bool hasMacro(string $name)
6565
* @method static void flushMacros()
6666
*
67-
* @see \Illuminate\Auth\AuthManager
68-
* @see \Illuminate\Auth\SessionGuard
67+
* @mixin \Illuminate\Auth\AuthManager
68+
* @mixin \Illuminate\Auth\SessionGuard
6969
*/
7070
class Auth extends Facade
7171
{

src/Illuminate/Support/Facades/Blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* @method static string compileEchos(string $value)
4646
* @method static string applyEchoHandler(string $value)
4747
*
48-
* @see \Illuminate\View\Compilers\BladeCompiler
48+
* @mixin \Illuminate\View\Compilers\BladeCompiler
4949
*/
5050
class Blade extends Facade
5151
{

src/Illuminate/Support/Facades/Broadcast.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
* @method static \Illuminate\Broadcasting\Broadcasters\Broadcaster channel(\Illuminate\Contracts\Broadcasting\HasBroadcastChannel|string $channel, callable|string $callback, array $options = [])
3434
* @method static \Illuminate\Support\Collection getChannels()
3535
*
36-
* @see \Illuminate\Broadcasting\BroadcastManager
37-
* @see \Illuminate\Broadcasting\Broadcasters\Broadcaster
36+
* @mixin \Illuminate\Broadcasting\BroadcastManager
37+
* @mixin \Illuminate\Broadcasting\Broadcasters\Broadcaster
3838
*/
3939
class Broadcast extends Facade
4040
{

src/Illuminate/Support/Facades/Bus.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
* @method static \Illuminate\Support\Testing\Fakes\BusFake serializeAndRestore(bool $serializeAndRestore = true)
5050
* @method static array dispatchedBatches()
5151
*
52-
* @see \Illuminate\Bus\Dispatcher
53-
* @see \Illuminate\Support\Testing\Fakes\BusFake
52+
* @mixin \Illuminate\Bus\Dispatcher
53+
* @mixin \Illuminate\Support\Testing\Fakes\BusFake
5454
*/
5555
class Bus extends Facade
5656
{

src/Illuminate/Support/Facades/Cache.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
* @method static \Illuminate\Contracts\Cache\Lock lock(string $name, int $seconds = 0, string|null $owner = null)
5454
* @method static \Illuminate\Contracts\Cache\Lock restoreLock(string $name, string $owner)
5555
*
56-
* @see \Illuminate\Cache\CacheManager
57-
*
56+
* @mixin \Illuminate\Cache\CacheManager
5857
* @mixin \Illuminate\Cache\Repository
5958
*/
6059
class Cache extends Facade

src/Illuminate/Support/Facades/Config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @method static bool hasMacro(string $name)
2121
* @method static void flushMacros()
2222
*
23-
* @see \Illuminate\Config\Repository
23+
* @mixin \Illuminate\Config\Repository
2424
*/
2525
class Config extends Facade
2626
{

src/Illuminate/Support/Facades/Context.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @method static void flushMacros()
3535
* @method static \Illuminate\Database\Eloquent\Model restoreModel(\Illuminate\Contracts\Database\ModelIdentifier $value)
3636
*
37-
* @see \Illuminate\Log\Context\Repository
37+
* @mixin \Illuminate\Log\Context\Repository
3838
*/
3939
class Context extends Facade
4040
{

src/Illuminate/Support/Facades/Cookie.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @method static bool hasMacro(string $name)
2020
* @method static void flushMacros()
2121
*
22-
* @see \Illuminate\Cookie\CookieJar
22+
* @mixin \Illuminate\Cookie\CookieJar
2323
*/
2424
class Cookie extends Facade
2525
{

0 commit comments

Comments
 (0)