Skip to content

[OptionsResolver] Updated some example code to use modern PHP #11012

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

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 5 additions & 16 deletions components/options_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,16 @@ check which options are set::
{
$mail = ...;

$mail->setHost(isset($this->options['host'])
? $this->options['host']
: 'smtp.example.org');

$mail->setUsername(isset($this->options['username'])
? $this->options['username']
: 'user');

$mail->setPassword(isset($this->options['password'])
? $this->options['password']
: 'pa$$word');

$mail->setPort(isset($this->options['port'])
? $this->options['port']
: 25);
$mail->setHost($this->options['host'] ?? 'smtp.example.org');
$mail->setUsername($this->options['username'] ?? 'user');
$mail->setPassword($this->options['password'] ?? 'pa$$word');
$mail->setPort($this->options['port'] ?? 25);

// ...
}
}

This boilerplate is hard to read and repetitive. Also, the default values of the
This boilerplate code is boring and repetitive. Also, the default values of the
options are buried in the business logic of your code. Use the
:phpfunction:`array_replace` to fix that::

Expand Down