| Conditions | 4 |
| Paths | 5 |
| Total Lines | 65 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 100 | protected function mail( string $subject, string $body ) : self |
||
| 101 | { |
||
| 102 | $config = $this->context->config(); |
||
| 103 | |||
| 104 | /** resource/email/from-name |
||
| 105 | * Name of the e-mail sender |
||
| 106 | * |
||
| 107 | * Should be the company or web site name |
||
| 108 | * |
||
| 109 | * @param string Sender name |
||
| 110 | * @see resource/email/from-email |
||
| 111 | */ |
||
| 112 | $name = $config->get( 'resource/email/from-name' ); |
||
| 113 | |||
| 114 | /** resource/email/from-email |
||
| 115 | * E-Mail address of the sender |
||
| 116 | * |
||
| 117 | * Should be the e-mail address of the company or web site |
||
| 118 | * |
||
| 119 | * @param string E-Mail address |
||
| 120 | * @see resource/email/from-name |
||
| 121 | */ |
||
| 122 | $email = $config->get( 'resource/email/from-email' ); |
||
| 123 | |||
| 124 | /** controller/jobs/to-email |
||
| 125 | * Recipient e-mail address used when sending job e-mails |
||
| 126 | * |
||
| 127 | * Job controllers can send e-mails when they has finished of if an |
||
| 128 | * error occurred. This setting will be used as the recipient e-mail |
||
| 129 | * address for these e-mails. |
||
| 130 | * |
||
| 131 | * @param string E-mail address |
||
| 132 | * @since 2020.04 |
||
| 133 | * @category User |
||
| 134 | * @see controller/jobs/from-email |
||
| 135 | */ |
||
| 136 | if( ( $to = $config->get( 'controller/jobs/to-email', $email ) ) == null ) { |
||
| 137 | return $this; |
||
| 138 | } |
||
| 139 | |||
| 140 | $message = $this->context->mail()->create(); |
||
| 141 | |||
| 142 | foreach( (array) $to as $addr ) { |
||
| 143 | $message->to( $addr, $name ); |
||
| 144 | } |
||
| 145 | |||
| 146 | /** controller/jobs/from-email |
||
| 147 | * Sender e-mail address used when sending job e-mails |
||
| 148 | * |
||
| 149 | * Job controllers can send e-mails when they has finished of if an |
||
| 150 | * error occurred. This setting will be used as the sender e-mail |
||
| 151 | * address in these e-mails. |
||
| 152 | * |
||
| 153 | * @param string E-mail address |
||
| 154 | * @since 2020.04 |
||
| 155 | * @category User |
||
| 156 | * @see controller/jobs/to-email |
||
| 157 | */ |
||
| 158 | if( $from = $config->get( 'controller/jobs/from-email', $email ) ) { |
||
| 159 | $message->from( $from, $name ); |
||
| 160 | } |
||
| 161 | |||
| 162 | $message->subject( $subject )->text( $body )->send(); |
||
| 163 | |||
| 164 | return $this; |
||
| 165 | } |
||
| 167 |