Skip to content

Commit

Permalink
Support yiisoft/mailer ^4.0 + minor improvements (#39)
Browse files Browse the repository at this point in the history
* fix changelog

* improve

* update dev dependencies

* Add support of `yiisoft/mailer` version `^4.0`

* remove scrutinizer config

* Apply fixes from StyleCI

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
vjik and StyleCIBot committed Dec 7, 2022
1 parent 55874de commit 1145a74
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 71 deletions.
35 changes: 0 additions & 35 deletions .scrutinizer.yml

This file was deleted.

15 changes: 8 additions & 7 deletions CHANGELOG.md
@@ -1,25 +1,26 @@
# Yii Log - Email Target Change Log

## 3.1.1 under development

- Enh: Add composer require checker into CI
## 4.0.0 under development

- Enh #39: In `EmailTarget` move type hints from phpdoc to constructor signature (@vjik)
- Enh #39: Add support of `yiisoft/mailer` version `^4.0` (@vjik)

## 3.1.0 May 23, 2022

- Chg #29: Raise the minimum `yiisoft/log` version to `^2.0` and the minimum PHP version to 8.0 (rustamwin)
- Chg #29: Raise the minimum `yiisoft/log` version to `^2.0` and the minimum PHP version to 8.0 (@rustamwin)

## 3.0.1 August 26, 2021

- Bug #28: Remove `Psr\Log\LoggerInterface` definition from configuration for using multiple targets to application (devanych)
- Bug #28: Remove `Psr\Log\LoggerInterface` definition from configuration for using multiple targets
to application (@devanych)

## 3.0.0 August 25, 2021

- Chg: Use yiisoft/mailer ^3.0 (samdark)
- Chg: Use `yiisoft/mailer` version `^3.0` (@samdark)

## 2.0.0 August 24, 2021

- Chg: Use yiisoft/mailer ^2.0 (samdark)
- Chg: Use `yiisoft/mailer` version `^2.0` (@samdark)

## 1.0.0 July 05, 2021

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@
[![Total Downloads](https://poser.pugx.org/yiisoft/log-target-email/downloads.png)](https://packagist.org/packages/yiisoft/log-target-email)
[![Build status](https://github.com/yiisoft/log-target-email/workflows/build/badge.svg)](https://github.com/yiisoft/log-target-email/actions?query=workflow%3Abuild)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/log-target-email/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/log-target-email/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/log-target-email/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/log-target-email/?branch=master)
[![Code Coverage](https://codecov.io/gh/yiisoft/log-target-email/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/log-target-email)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Flog-target-email%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/log-target-email/master)
[![static analysis](https://github.com/yiisoft/log-target-email/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/log-target-email/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/log-target-email/coverage.svg)](https://shepherd.dev/github/yiisoft/log-target-email)
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Expand Up @@ -21,16 +21,16 @@
"require": {
"php": "^8.0",
"yiisoft/log": "^2.0",
"yiisoft/mailer": "^3.0"
"yiisoft/mailer": "^3.0|^4.0"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"maglnet/composer-require-checker": "^4.3",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.3",
"roave/infection-static-analysis-plugin": "^1.16",
"rector/rector": "^0.15.0",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
"yiisoft/event-dispatcher": "^1.0"
"vimeo/psalm": "^4.30|^5.1",
"yiisoft/event-dispatcher": "^1.1"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 8 additions & 13 deletions src/EmailTarget.php
Expand Up @@ -10,8 +10,6 @@
use Yiisoft\Log\Target;
use Yiisoft\Mailer\MailerInterface;

use function is_array;
use function is_string;
use function wordwrap;

/**
Expand All @@ -22,8 +20,7 @@
final class EmailTarget extends Target
{
/**
* @var array|string The receiver email address.
* @psalm-var array<array-key, string>|string
* @var string|string[] The receiver email address.
* You may pass an array of addresses if multiple recipients should receive this message.
* You may also specify receiver name in addition to email address using format: `[email => name]`.
*/
Expand All @@ -36,21 +33,19 @@ final class EmailTarget extends Target

/**
* @param MailerInterface $mailer The mailer instance.
* @param array|string $emailTo The receiver email address.
* @psalm-param array<array-key, string>|string $emailTo
* @param string|string[] $emailTo The receiver email address.
* You may pass an array of addresses if multiple recipients should receive this message.
* You may also specify receiver name in addition to email address using format: `[email => name]`.
*
* @param string $subjectEmail The email message subject.
*
* @throws InvalidArgumentException If the "to" email message argument is invalid.
*
* @psalm-suppress DocblockTypeContradiction
*/
public function __construct(private MailerInterface $mailer, $emailTo, string $subjectEmail = '')
{
/** @psalm-suppress TypeDoesNotContainType */
if (empty($emailTo) || (!is_string($emailTo) && !is_array($emailTo))) {
public function __construct(
private MailerInterface $mailer,
array|string $emailTo,
string $subjectEmail = ''
) {
if (empty($emailTo)) {
throw new InvalidArgumentException('The "to" argument must be an array or string and must not be empty.');
}
$this->emailTo = $emailTo;
Expand Down
12 changes: 3 additions & 9 deletions tests/EmailTargetTest.php
Expand Up @@ -5,12 +5,12 @@
namespace Yiisoft\Log\Target\Email\Tests;

use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LogLevel;
use ReflectionException;
use ReflectionObject;
use RuntimeException;
use stdClass;
use Yiisoft\Log\Message;
use Yiisoft\Log\Target\Email\EmailTarget;
use Yiisoft\Mailer\Mailer;
Expand All @@ -20,9 +20,8 @@

final class EmailTargetTest extends TestCase
{
private \Yiisoft\Mailer\Mailer|\PHPUnit\Framework\MockObject\MockObject $mailer;

private \Yiisoft\Mailer\MessageInterface|\PHPUnit\Framework\MockObject\MockObject $message;
private Mailer|MockObject $mailer;
private MessageInterface|MockObject $message;

/**
* Set up mailer.
Expand Down Expand Up @@ -161,11 +160,6 @@ public function testExportWithSendFailure(): void
public function invalidEmailToDataProvider(): array
{
return [
'int' => [1],
'float' => [1.1],
'null' => [null],
'object' => [new stdClass()],
'callable' => [fn () => 'admin@example.com'],
'empty-array' => [[]],
'empty-string' => [''],
];
Expand Down

0 comments on commit 1145a74

Please sign in to comment.