Skip to content

Commit

Permalink
Merge pull request #34 from yiisoft/add-rector
Browse files Browse the repository at this point in the history
Add rector [batch]
  • Loading branch information
xepozz committed Oct 28, 2022
2 parents 6a9cc8d + b0c8f46 commit 55874de
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 32 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
@@ -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']
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -26,6 +26,7 @@
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.3",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
Expand Down
22 changes: 22 additions & 0 deletions rector.php
@@ -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,
]);
};
11 changes: 2 additions & 9 deletions src/EmailTarget.php
Expand Up @@ -21,18 +21,13 @@
*/
final class EmailTarget extends Target
{
/**
* @var MailerInterface The mailer instance.
*/
private MailerInterface $mailer;

/**
* @var array|string The receiver email address.
* @psalm-var array<array-key, string>|string
* 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]`.
*/
private $emailTo;
private array|string $emailTo;

/**
* @var string The email message subject.
Expand All @@ -52,14 +47,12 @@ final class EmailTarget extends Target
*
* @psalm-suppress DocblockTypeContradiction
*/
public function __construct(MailerInterface $mailer, $emailTo, string $subjectEmail = '')
public function __construct(private MailerInterface $mailer, $emailTo, string $subjectEmail = '')
{
/** @psalm-suppress TypeDoesNotContainType */
if (empty($emailTo) || (!is_string($emailTo) && !is_array($emailTo))) {
throw new InvalidArgumentException('The "to" argument must be an array or string and must not be empty.');
}

$this->mailer = $mailer;
$this->emailTo = $emailTo;
$this->subjectEmail = $subjectEmail ?: 'Application Log';
parent::__construct();
Expand Down
27 changes: 4 additions & 23 deletions tests/EmailTargetTest.php
Expand Up @@ -6,7 +6,6 @@

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LogLevel;
use ReflectionException;
use ReflectionObject;
Expand All @@ -21,15 +20,9 @@

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

/**
* @var MessageInterface|MockObject
*/
private $message;
private \Yiisoft\Mailer\MessageInterface|\PHPUnit\Framework\MockObject\MockObject $message;

/**
* Set up mailer.
Expand Down Expand Up @@ -180,24 +173,16 @@ public function invalidEmailToDataProvider(): array

/**
* @dataProvider invalidEmailToDataProvider
*
* @param mixed $emailTo
*/
public function testConstructThrownExceptionForInvalidEmailTo($emailTo): void
public function testConstructThrownExceptionForInvalidEmailTo(mixed $emailTo): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "to" argument must be an array or string and must not be empty.');

new EmailTarget($this->mailer, $emailTo);
}

/**
* @param mixed $emailTo
* @param string $subjectEmail
*
* @return EmailTarget
*/
private function createEmailTarget($emailTo, string $subjectEmail = ''): EmailTarget
private function createEmailTarget(mixed $emailTo, string $subjectEmail = ''): EmailTarget
{
$target = new EmailTarget($this->mailer, $emailTo, $subjectEmail);
$target->setFormat(fn (Message $message) => "[{$message->level()}] {$message->message()}");
Expand All @@ -207,11 +192,7 @@ private function createEmailTarget($emailTo, string $subjectEmail = ''): EmailTa
/**
* Invokes the `EmailTarget::formatMessages()` protected method.
*
* @param EmailTarget $target
*
* @throws ReflectionException
*
* @return string
*/
private function invokeFormatMessagesMethod(EmailTarget $target): string
{
Expand Down

0 comments on commit 55874de

Please sign in to comment.