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

[11.x] Utilize null-safe operator instead of conditional check #51328

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 4 additions & 12 deletions src/Illuminate/Database/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ public function runPending(array $migrations, array $options = [])

$this->fireMigrationEvent(new MigrationsEnded('up'));

if ($this->output) {
$this->output->writeln('');
}
$this->output?->writeln('');
}

/**
Expand Down Expand Up @@ -242,9 +240,7 @@ public function rollback($paths = [], array $options = [])
}

return tap($this->rollbackMigrations($migrations, $paths, $options), function () {
if ($this->output) {
$this->output->writeln('');
}
$this->output?->writeln('');
Copy link

@bulletproof-coding bulletproof-coding May 8, 2024

Choose a reason for hiding this comment

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

Safest way is

if (isset($this->output) && $this->output instanceof \Symfony\Component\Console\Output\OutputInterface) {

Because the property is not typed hinted and it could be of another type and because it could be accessed before initialization.
This is valid also for the other changes.

PS.
I forgot to hit submit review before merge...

});
}

Expand Down Expand Up @@ -331,9 +327,7 @@ public function reset($paths = [], $pretend = false)
}

return tap($this->resetMigrations($migrations, Arr::wrap($paths), $pretend), function () {
if ($this->output) {
$this->output->writeln('');
}
$this->output?->writeln('');
});
}

Expand Down Expand Up @@ -760,8 +754,6 @@ protected function write($component, ...$arguments)
*/
public function fireMigrationEvent($event)
{
if ($this->events) {
$this->events->dispatch($event);
}
$this->events?->dispatch($event);
}
}
8 changes: 3 additions & 5 deletions src/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,9 @@ protected function shouldSendMessage($message, $data = [])
*/
protected function dispatchSentEvent($message, $data = [])
{
if ($this->events) {
$this->events->dispatch(
new MessageSent($message, $data)
);
}
$this->events?->dispatch(
new MessageSent($message, $data)
);
}

/**
Expand Down