Skip to content
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