Skip to content
Snippets Groups Projects
Commit 4932c63b authored by Piotr Potrebka's avatar Piotr Potrebka
Browse files

feat: refactor

parent 74b58921
No related branches found
No related tags found
1 merge request!5Devel
Pipeline #432322 passed with warnings with stages
in 36 seconds
## [1.0.0] - 2023-03-06 ## [1.0.0] - 2024-10-23
### Added ### Added
- init - init
...@@ -9,42 +9,42 @@ class Email { ...@@ -9,42 +9,42 @@ class Email {
/** /**
* @var array * @var array
*/ */
private $recipients = []; private array $recipients = [];
/** /**
* @var string * @var string
*/ */
private $subject = ''; private string $subject = '';
/** /**
* @var array * @var array
*/ */
private $attachments = []; private array $attachments = [];
/** /**
* @var string * @var string
*/ */
private $content = ''; private string $content = '';
/** /**
* @var array * @var array
*/ */
private $headers = [ 'Content-Type' => 'text/html' ]; private array $headers = [ 'Content-Type' => 'text/html' ];
/** /**
* @var string * @var string
*/ */
private $from_email; private string $from_email;
/** /**
* @var string * @var string
*/ */
private $from_name; private string $from_name;
/** /**
* @var array * @var array
*/ */
private $template_attributes; private array $template_attributes;
/** /**
* @param string $from_email * @param string $from_email
...@@ -162,7 +162,9 @@ class Email { ...@@ -162,7 +162,9 @@ class Email {
} }
/** /**
* @return string * @param $type
*
* @return Email
*/ */
public function set_content_type( $type ): self { public function set_content_type( $type ): self {
switch ( $type ) { switch ( $type ) {
...@@ -201,13 +203,12 @@ class Email { ...@@ -201,13 +203,12 @@ class Email {
} }
/** /**
* @param string $name * @param array $template_attributes
* @param string $value
* *
* @return $this * @return $this
*/ */
public function set_template_attributes( string $name, string $value ): self { public function set_template_attributes( array $template_attributes ): self {
$this->template_attributes[ $name ] = $value; $this->template_attributes= $template_attributes;
return $this; return $this;
} }
......
...@@ -4,9 +4,12 @@ declare( strict_types=1 ); ...@@ -4,9 +4,12 @@ declare( strict_types=1 );
namespace WPDesk\Library\WPEmail\Exceptions; namespace WPDesk\Library\WPEmail\Exceptions;
class MailerException extends \RuntimeException { use RuntimeException;
use WP_Error;
public static function with_wp_error( \WP_Error $error ): self { class MailerException extends RuntimeException {
public static function with_wp_error( WP_Error $error ): self {
$errors = $error->get_error_messages( 'wp_mail_failed' ); $errors = $error->get_error_messages( 'wp_mail_failed' );
$message = implode( "\n", $errors ); $message = implode( "\n", $errors );
......
...@@ -14,17 +14,17 @@ class Template { ...@@ -14,17 +14,17 @@ class Template {
/** /**
* @var LoggerInterface * @var LoggerInterface
*/ */
private $logger; private LoggerInterface $logger;
/** /**
* @var Renderer * @var Renderer
*/ */
private $renderer; private Renderer $renderer;
/** /**
* @var array * @var array
*/ */
private $template_attributes; private array $template_attributes;
public function __construct( LoggerInterface $logger, Renderer $renderer, array $template_attributes ) { public function __construct( LoggerInterface $logger, Renderer $renderer, array $template_attributes ) {
$this->logger = $logger; $this->logger = $logger;
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace WPDesk\Library\WPEmail; namespace WPDesk\Library\WPEmail;
use Exception; use Exception;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use WP_Error; use WP_Error;
use WPDesk\Library\WPEmail\Abstracts\Email; use WPDesk\Library\WPEmail\Abstracts\Email;
...@@ -19,21 +18,21 @@ class WPMailer implements Mailer { ...@@ -19,21 +18,21 @@ class WPMailer implements Mailer {
/** /**
* @var LoggerInterface * @var LoggerInterface
*/ */
private $logger; private LoggerInterface $logger;
/** /**
* @var Renderer * @var Renderer
*/ */
private $renderer; private Renderer $renderer;
public function __construct( LoggerInterface $logger ) { public function __construct( LoggerInterface $logger ) {
$this->logger = $logger; $this->logger = $logger;
$this->init_renderer(); $this->init_renderer();
} }
public function init_renderer() { public function init_renderer() {
$resolver = new ChainResolver(); $resolver = new ChainResolver();
$resolver->appendResolver( new DirResolver( __DIR__ . '/templates' ) ); $resolver->appendResolver( new DirResolver( dirname( __DIR__ ) . '/templates' ) );
$renderer = new SimplePhpRenderer( $resolver ); $renderer = new SimplePhpRenderer( $resolver );
$this->set_renderer( $renderer ); $this->set_renderer( $renderer );
} }
...@@ -46,7 +45,11 @@ class WPMailer implements Mailer { ...@@ -46,7 +45,11 @@ class WPMailer implements Mailer {
return $this->renderer; return $this->renderer;
} }
/** @return void */ /**
* @param Email $email
*
* @return void
*/
public function send( Email $email ): void { public function send( Email $email ): void {
$mailer_from = $email->get_from(); $mailer_from = $email->get_from();
add_filter( add_filter(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment