Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 21 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Yii Mailer Library

## 4.1.0 under development
## 5.0.0 under development

- Chg #60: Raise minimal PHP version to `^8.0` (@vjik)
- Enh #56: Add support of `yiisoft/view` of version `^7.0` (@vjik)
- Enh #56: Add support of `yiisoft/view` of version `^7.0` (@vjik)
- Chg #52: In `MessageInterface` methods move a type hints from annotation to signature (@vjik)

## 4.0.0 July 23, 2022

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"require-dev": {
"maglnet/composer-require-checker": "^4.4",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.15.2",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.4",
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);
};
5 changes: 1 addition & 4 deletions src/Event/AfterSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
*/
final class AfterSend
{
private MessageInterface $message;

public function __construct(MessageInterface $message)
public function __construct(private MessageInterface $message)
{
$this->message = $message;
}

public function getMessage(): MessageInterface
Expand Down
4 changes: 1 addition & 3 deletions src/Event/BeforeSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
*/
final class BeforeSend implements StoppableEventInterface
{
private MessageInterface $message;
private bool $stopPropagation = false;

public function __construct(MessageInterface $message)
public function __construct(private MessageInterface $message)
{
$this->message = $message;
}

public function getMessage(): MessageInterface
Expand Down
36 changes: 6 additions & 30 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,18 @@ final class File
*/
private ?string $id = null;

/**
* @var string|null The name that should be used to attach the file.
*/
private ?string $name;

/**
* @var string|null The full path to the file.
*/
private ?string $path;

/**
* @var string|null The content that should be used to attach the file.
*/
private ?string $content;

/**
* @var string|null MIME type that should be used to attach the file.
*/
private ?string $contentType;

/**
* @param string|null $name The name that should be used to attach the file.
* @param string|null $path The full path to the file.
* @param string|null $content The content that should be used to attach the file.
* @param string|null $contentType MIME type that should be used to attach the file.
*/
private function __construct(?string $name, ?string $path, ?string $content, ?string $contentType)
{
$this->name = $name;
$this->path = $path;
$this->content = $content;
$this->contentType = $contentType;
private function __construct(
private ?string $name,
private ?string $path,
private ?string $content,
private ?string $contentType
) {
}

/**
Expand All @@ -61,8 +41,6 @@ private function __construct(?string $name, ?string $path, ?string $content, ?st
* @param string $content The content that should be used to attach the file.
* @param string|null $name The name that should be used to attach the file.
* @param string|null $contentType MIME type that should be used to attach the file.
*
* @return self
*/
public static function fromContent(string $content, string $name = null, string $contentType = null): self
{
Expand All @@ -77,8 +55,6 @@ public static function fromContent(string $content, string $name = null, string
* @param string|null $contentType MIME type that should be used to attach the file.
*
* @throws RuntimeException If the specified file does not exist.
*
* @return self
*/
public static function fromPath(string $path, string $name = null, string $contentType = null): self
{
Expand Down
10 changes: 1 addition & 9 deletions src/FileMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
*/
final class FileMailer extends Mailer
{
/**
* The path where message files located.
*
* @var string
*/
private string $path;

/**
* @var callable|null A PHP callback that return a file name which will be used to save the email message.
*
Expand All @@ -57,11 +50,10 @@ public function __construct(
MessageFactoryInterface $messageFactory,
MessageBodyRenderer $messageBodyRenderer,
EventDispatcherInterface $eventDispatcher,
string $path,
private string $path,
callable $filenameCallback = null
) {
parent::__construct($messageFactory, $messageBodyRenderer, $eventDispatcher);
$this->path = $path;
$this->filenameCallback = $filenameCallback;
}

Expand Down
13 changes: 3 additions & 10 deletions src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@
*/
abstract class Mailer implements MailerInterface
{
private MessageFactoryInterface $messageFactory;
private MessageBodyRenderer $messageBodyRenderer;
private EventDispatcherInterface $eventDispatcher;

public function __construct(
MessageFactoryInterface $messageFactory,
MessageBodyRenderer $messageBodyRenderer,
EventDispatcherInterface $eventDispatcher
private MessageFactoryInterface $messageFactory,
private MessageBodyRenderer $messageBodyRenderer,
private EventDispatcherInterface $eventDispatcher
) {
$this->messageFactory = $messageFactory;
$this->messageBodyRenderer = $messageBodyRenderer;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down
22 changes: 5 additions & 17 deletions src/MessageBodyRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,14 @@
*/
final class MessageBodyRenderer
{
/**
* @var View The view instance.
*/
private View $view;

/**
* @var MessageBodyTemplate The message body template instance.
*/
private MessageBodyTemplate $template;

/**
* @param View $view The view instance.
* @param MessageBodyTemplate $template The message body template instance.
*/
public function __construct(View $view, MessageBodyTemplate $template)
{
$this->view = $view;
$this->template = $template;
public function __construct(
private View $view,
private MessageBodyTemplate $template
) {
}

/**
Expand All @@ -68,7 +58,7 @@ public function __construct(View $view, MessageBodyTemplate $template)
*/
public function addToMessage(
MessageInterface $message,
$view,
mixed $view,
array $viewParameters = [],
array $layoutParameters = []
): MessageInterface {
Expand Down Expand Up @@ -196,8 +186,6 @@ public function withTemplate(MessageBodyTemplate $template): self
* Returns a new instance with specified locale code.
*
* @param string $locale The locale code.
*
* @return self
*/
public function withLocale(string $locale): self
{
Expand Down
36 changes: 8 additions & 28 deletions src/MessageBodyTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,27 @@
final class MessageBodyTemplate implements ViewContextInterface
{
/**
* @var string The directory containing view files for composing mail messages.
*/
private string $viewPath;

/**
* @var string The HTML layout view name.
*
* It is the layout used to render HTML mail body. If the value is empty string, no layout will be applied.
* @param string $viewPath The directory containing view files for composing mail messages.
* @param string $htmlLayout The HTML layout view name. It is the layout used to render HTML mail body. If the value
* is empty string, no layout will be applied.
*
* The property can take the following values:
*
* - a relative view name: a view file relative to {@see MessageBodyRenderer::$viewPath}, e.g., 'layouts/html'.
* - an empty string: the layout is disabled.
*/
private string $htmlLayout;

/**
* @var string The TEXT layout view name.
*
* This is the layout used to render TEXT mail body. If the value is empty string, no layout will be applied.
* @param string $textLayout The TEXT layout view name. This is the layout used to render TEXT mail body. If the
* value is empty string, no layout will be applied.
*
* The property can take the following values:
*
* - a relative view name: a view file relative to {@see MessageBodyRenderer::$viewPath}, e.g., 'layouts/text'.
* - an empty string: the layout is disabled.
*/
private string $textLayout;

/**
* @param string $viewPath The directory containing view files for composing mail messages.
* @param string $htmlLayout The HTML layout view name. It is the layout used to render HTML mail body.
* @param string $textLayout The TEXT layout view name. This is the layout used to render TEXT mail body.
*/
public function __construct(
string $viewPath,
string $htmlLayout = 'layouts/html',
string $textLayout = 'layouts/text'
private string $viewPath,
private string $htmlLayout = 'layouts/html',
private string $textLayout = 'layouts/text'
) {
$this->viewPath = $viewPath;
$this->htmlLayout = $htmlLayout;
$this->textLayout = $textLayout;
}

/**
Expand Down
Loading