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
This commit is part of merge request !5. Comments created here will be created in the context of that merge request.
## [1.0.0] - 2023-03-06
## [1.0.0] - 2024-10-23
### Added
- init
......@@ -9,42 +9,42 @@ class Email {
/**
* @var array
*/
private $recipients = [];
private array $recipients = [];
/**
* @var string
*/
private $subject = '';
private string $subject = '';
/**
* @var array
*/
private $attachments = [];
private array $attachments = [];
/**
* @var string
*/
private $content = '';
private string $content = '';
/**
* @var array
*/
private $headers = [ 'Content-Type' => 'text/html' ];
private array $headers = [ 'Content-Type' => 'text/html' ];
/**
* @var string
*/
private $from_email;
private string $from_email;
/**
* @var string
*/
private $from_name;
private string $from_name;
/**
* @var array
*/
private $template_attributes;
private array $template_attributes;
/**
* @param string $from_email
......@@ -162,7 +162,9 @@ class Email {
}
/**
* @return string
* @param $type
*
* @return Email
*/
public function set_content_type( $type ): self {
switch ( $type ) {
......@@ -201,13 +203,12 @@ class Email {
}
/**
* @param string $name
* @param string $value
* @param array $template_attributes
*
* @return $this
*/
public function set_template_attributes( string $name, string $value ): self {
$this->template_attributes[ $name ] = $value;
public function set_template_attributes( array $template_attributes ): self {
$this->template_attributes= $template_attributes;
return $this;
}
......
......@@ -4,9 +4,12 @@ declare( strict_types=1 );
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' );
$message = implode( "\n", $errors );
......
......@@ -14,17 +14,17 @@ class Template {
/**
* @var LoggerInterface
*/
private $logger;
private LoggerInterface $logger;
/**
* @var Renderer
*/
private $renderer;
private Renderer $renderer;
/**
* @var array
*/
private $template_attributes;
private array $template_attributes;
public function __construct( LoggerInterface $logger, Renderer $renderer, array $template_attributes ) {
$this->logger = $logger;
......
......@@ -3,7 +3,6 @@
namespace WPDesk\Library\WPEmail;
use Exception;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use WP_Error;
use WPDesk\Library\WPEmail\Abstracts\Email;
......@@ -19,21 +18,21 @@ class WPMailer implements Mailer {
/**
* @var LoggerInterface
*/
private $logger;
private LoggerInterface $logger;
/**
* @var Renderer
*/
private $renderer;
private Renderer $renderer;
public function __construct( LoggerInterface $logger ) {
$this->logger = $logger;
$this->init_renderer();
$this->logger = $logger;
$this->init_renderer();
}
public function init_renderer() {
$resolver = new ChainResolver();
$resolver->appendResolver( new DirResolver( __DIR__ . '/templates' ) );
$resolver->appendResolver( new DirResolver( dirname( __DIR__ ) . '/templates' ) );
$renderer = new SimplePhpRenderer( $resolver );
$this->set_renderer( $renderer );
}
......@@ -46,7 +45,11 @@ class WPMailer implements Mailer {
return $this->renderer;
}
/** @return void */
/**
* @param Email $email
*
* @return void
*/
public function send( Email $email ): void {
$mailer_from = $email->get_from();
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