Skip to content

Commit

Permalink
[11.x] chore: update to PHPStan Level 1 (laravel#51956)
Browse files Browse the repository at this point in the history
* chore: update to phpstan level 1

* chore: update facades to use @mixin

* fix: HasAttributes::relationsToArray isset logic
  • Loading branch information
calebdw authored Aug 1, 2024
1 parent cac7d24 commit 582955c
Show file tree
Hide file tree
Showing 72 changed files with 135 additions and 104 deletions.
3 changes: 2 additions & 1 deletion phpstan.src.neon.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
parameters:
level: 0
level: 1
paths:
- src
excludePaths:
- src/Illuminate/Testing/ParallelRunner.php
- src/*/views/*
ignoreErrors:
- "#\\(void\\) is used#"
- "#Access to an undefined property#"
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ protected function callBeforeCallbacks($user, $ability, array $arguments)
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param string $ability
* @param array $arguments
* @param bool $result
* @param bool|null $result
* @return bool|null
*/
protected function callAfterCallbacks($user, $ability, array $arguments, $result)
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Bus/PendingBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,7 @@ protected function dispatchExistingBatch($batch)
try {
$batch = $batch->add($this->jobs);
} catch (Throwable $e) {
if (isset($batch)) {
$batch->delete();
}
$batch->delete();

throw $e;
}
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Cache/RetrievesMultipleKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function many(array $keys)
})->all();

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

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public function hasAny($key)
/**
* Concatenate values of a given key as a string.
*
* @param callable|string $value
* @param callable|string|null $value
* @param string|null $glue
* @return string
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ protected function createPdoResolverWithHosts(array $config)
}
}

throw $e;
if (isset($e)) {
throw $e;
}
};
}

Expand Down
8 changes: 3 additions & 5 deletions src/Illuminate/Database/Connectors/MySqlConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ protected function getSocketDsn(array $config)
*/
protected function getHostDsn(array $config)
{
extract($config, EXTR_SKIP);

return isset($port)
? "mysql:host={$host};port={$port};dbname={$database}"
: "mysql:host={$host};dbname={$database}";
return isset($config['port'])
? "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}"
: "mysql:host={$config['host']};dbname={$config['database']}";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Connectors/PostgresConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function getDsn(array $config)
// Sometimes - users may need to connect to a database that has a different
// name than the database used for "information_schema" queries. This is
// typically the case if using "pgbouncer" type software when pooling.
$database = $connect_via_database ?? $database;
$database = $connect_via_database ?? $database ?? null;
$port = $connect_via_port ?? $port ?? null;

$dsn = "pgsql:{$host}dbname='{$database}'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function getConnectionCount(ConnectionInterface $connection)
/**
* Get the connection configuration details for the given connection.
*
* @param string $database
* @param string|null $database
* @return array
*/
protected function getConfigFromDatabase($database)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Attributes/ObservedBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ObservedBy
* @param array|string $classes
* @return void
*/
public function __construct(array|string $classes)
public function __construct(public array|string $classes)
{
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Attributes/ScopedBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ScopedBy
* @param array|string $classes
* @return void
*/
public function __construct(array|string $classes)
public function __construct(public array|string $classes)
{
}
}
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ public function relationsToArray()
// If the relation value has been set, we will set it on this attributes
// list for returning. If it was not arrayable or null, we'll not set
// the value on the array because it is some type of invalid value.
if (isset($relation) || is_null($value)) {
$attributes[$key] = $relation;
if (array_key_exists('relation', get_defined_vars())) { // check if $relation is in scope (could be null)
$attributes[$key] = $relation ?? null;
}

unset($relation);
Expand Down Expand Up @@ -1208,7 +1208,7 @@ protected function setClassCastableAttribute($key, $value)
* Set the value of an enum castable attribute.
*
* @param string $key
* @param \UnitEnum|string|int $value
* @param \UnitEnum|string|int|null $value
* @return void
*/
protected function setEnumCastableAttribute($key, $value)
Expand Down Expand Up @@ -1326,7 +1326,7 @@ protected function asJson($value)
/**
* Decode the given JSON back into an array or object.
*
* @param string $value
* @param string|null $value
* @param bool $asObject
* @return mixed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ protected function morphEagerTo($name, $type, $id, $ownerKey)
* @param string $name
* @param string $type
* @param string $id
* @param string $ownerKey
* @param string|null $ownerKey
* @return \Illuminate\Database\Eloquent\Relations\MorphTo<\Illuminate\Database\Eloquent\Model, $this>
*/
protected function morphInstanceTo($target, $name, $type, $id, $ownerKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected function newOneOfManySubQuery($groupBy, $columns = null, $aggregate =
}
}

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

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

$this->addOneOfManyJoinSubQueryConstraints($join, $on);
$this->addOneOfManyJoinSubQueryConstraints($join);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Builder implements BuilderContract
/**
* The number of records to skip.
*
* @var int
* @var int|null
*/
public $offset;

Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function hasTable($table)
{
$table = $this->connection->getTablePrefix().$table;

/** @phpstan-ignore arguments.count (SQLite accepts a withSize argument) */
foreach ($this->getTables(false) as $value) {
if (strtolower($table) === strtolower($value['name'])) {
return true;
Expand Down
5 changes: 2 additions & 3 deletions src/Illuminate/Database/Schema/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,12 @@ public function wrapTable($table)
* Wrap a value in keyword identifiers.
*
* @param \Illuminate\Support\Fluent|\Illuminate\Contracts\Database\Query\Expression|string $value
* @param bool $prefixAlias
* @return string
*/
public function wrap($value, $prefixAlias = false)
public function wrap($value)
{
return parent::wrap(
$value instanceof Fluent ? $value->name : $value, $prefixAlias
$value instanceof Fluent ? $value->name : $value,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/DownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function getDownFilePayload()
'retry' => $this->getRetryTime(),
'refresh' => $this->option('refresh'),
'secret' => $this->getSecret(),
'status' => (int) $this->option('status', 503),
'status' => (int) ($this->option('status') ?? 503),
'template' => $this->option('render') ? $this->prerenderView() : null,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/stubs/facade.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace DummyNamespace;
use Illuminate\Support\Facades\Facade;

/**
* @see \DummyTarget
* @mixin \DummyTarget
*/
class DummyClass extends Facade
{
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Hashing/HashManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,14 @@ public function getDefaultDriver()
{
return $this->config->get('hashing.driver', 'bcrypt');
}

/**
* Verifies that the configuration is less than or equal to what is configured.
*
* @internal
*/
public function verifyConfiguration($value)
{
return $this->driver()->verifyConfiguration($value);
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Http/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function storePublicly($path = '', $options = [])
* Store the uploaded file on a filesystem disk with public visibility.
*
* @param string $path
* @param string $name
* @param array|string|null $name
* @param array|string $options
* @return string|false
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ protected function parseView($view)
* Add the content to a given message.
*
* @param \Illuminate\Mail\Message $message
* @param string $view
* @param string $plain
* @param string $raw
* @param string|null $view
* @param string|null $plain
* @param string|null $raw
* @param array $data
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/Messages/SimpleMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function with($line)
/**
* Format the given line of text.
*
* @param \Illuminate\Contracts\Support\Htmlable|string|array $line
* @param \Illuminate\Contracts\Support\Htmlable|string|array|null $line
* @return \Illuminate\Contracts\Support\Htmlable|string
*/
protected function formatLine($line)
Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Routing/Middleware/SubstituteBindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public function __construct(Registrar $router)
*/
public function handle($request, Closure $next)
{
try {
$this->router->substituteBindings($route = $request->route());
$route = $request->route();

try {
$this->router->substituteBindings($route);
$this->router->substituteImplicitBindings($route);
} catch (ModelNotFoundException $exception) {
if ($route->getMissing()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public function getPrefix()
/**
* Add a prefix to the route URI.
*
* @param string $prefix
* @param string|null $prefix
* @return $this
*/
public function prefix($prefix)
Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Routing/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ public function add(Route $route)
*/
protected function addToCollections($route)
{
$methods = $route->methods();
$domainAndUri = $route->getDomain().$route->uri();

foreach ($route->methods() as $method) {
foreach ($methods as $method) {
$this->routes[$method][$domainAndUri] = $route;
}

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

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Facades/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
* @method static bool hasMacro(string $name)
* @method static void flushMacros()
*
* @see \Illuminate\Foundation\Application
* @mixin \Illuminate\Foundation\Application
*/
class App extends Facade
{
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Facades/Artisan.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @method static \Illuminate\Foundation\Console\Kernel addCommandPaths(array $paths)
* @method static \Illuminate\Foundation\Console\Kernel addCommandRoutePaths(array $paths)
*
* @see \Illuminate\Foundation\Console\Kernel
* @mixin \Illuminate\Foundation\Console\Kernel
*/
class Artisan extends Facade
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Facades/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
* @method static bool hasMacro(string $name)
* @method static void flushMacros()
*
* @see \Illuminate\Auth\AuthManager
* @see \Illuminate\Auth\SessionGuard
* @mixin \Illuminate\Auth\AuthManager
* @mixin \Illuminate\Auth\SessionGuard
*/
class Auth extends Facade
{
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Facades/Blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @method static string compileEchos(string $value)
* @method static string applyEchoHandler(string $value)
*
* @see \Illuminate\View\Compilers\BladeCompiler
* @mixin \Illuminate\View\Compilers\BladeCompiler
*/
class Blade extends Facade
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Facades/Broadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
* @method static \Illuminate\Broadcasting\Broadcasters\Broadcaster channel(\Illuminate\Contracts\Broadcasting\HasBroadcastChannel|string $channel, callable|string $callback, array $options = [])
* @method static \Illuminate\Support\Collection getChannels()
*
* @see \Illuminate\Broadcasting\BroadcastManager
* @see \Illuminate\Broadcasting\Broadcasters\Broadcaster
* @mixin \Illuminate\Broadcasting\BroadcastManager
* @mixin \Illuminate\Broadcasting\Broadcasters\Broadcaster
*/
class Broadcast extends Facade
{
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Facades/Bus.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
* @method static \Illuminate\Support\Testing\Fakes\BusFake serializeAndRestore(bool $serializeAndRestore = true)
* @method static array dispatchedBatches()
*
* @see \Illuminate\Bus\Dispatcher
* @see \Illuminate\Support\Testing\Fakes\BusFake
* @mixin \Illuminate\Bus\Dispatcher
* @mixin \Illuminate\Support\Testing\Fakes\BusFake
*/
class Bus extends Facade
{
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Support/Facades/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
* @method static \Illuminate\Contracts\Cache\Lock lock(string $name, int $seconds = 0, string|null $owner = null)
* @method static \Illuminate\Contracts\Cache\Lock restoreLock(string $name, string $owner)
*
* @see \Illuminate\Cache\CacheManager
*
* @mixin \Illuminate\Cache\CacheManager
* @mixin \Illuminate\Cache\Repository
*/
class Cache extends Facade
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Facades/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @method static bool hasMacro(string $name)
* @method static void flushMacros()
*
* @see \Illuminate\Config\Repository
* @mixin \Illuminate\Config\Repository
*/
class Config extends Facade
{
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Facades/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @method static void flushMacros()
* @method static \Illuminate\Database\Eloquent\Model restoreModel(\Illuminate\Contracts\Database\ModelIdentifier $value)
*
* @see \Illuminate\Log\Context\Repository
* @mixin \Illuminate\Log\Context\Repository
*/
class Context extends Facade
{
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Facades/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @method static bool hasMacro(string $name)
* @method static void flushMacros()
*
* @see \Illuminate\Cookie\CookieJar
* @mixin \Illuminate\Cookie\CookieJar
*/
class Cookie extends Facade
{
Expand Down
Loading

0 comments on commit 582955c

Please sign in to comment.