Skip to content

Commit 55874de

Browse files
authored
Merge pull request #34 from yiisoft/add-rector
Add rector [batch]
2 parents 6a9cc8d + b0c8f46 commit 55874de

5 files changed

Lines changed: 50 additions & 32 deletions

File tree

.github/workflows/rector.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
on:
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'infection.json.dist'
10+
- 'psalm.xml'
11+
12+
name: rector
13+
14+
jobs:
15+
rector:
16+
uses: yiisoft/actions/.github/workflows/rector.yml@master
17+
with:
18+
os: >-
19+
['ubuntu-latest']
20+
php: >-
21+
['8.0']

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"require-dev": {
2727
"maglnet/composer-require-checker": "^4.2",
2828
"phpunit/phpunit": "^9.5",
29+
"rector/rector": "^0.14.3",
2930
"roave/infection-static-analysis-plugin": "^1.16",
3031
"spatie/phpunit-watcher": "^1.23",
3132
"vimeo/psalm": "^4.18",

rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->paths([
11+
__DIR__ . '/src',
12+
__DIR__ . '/tests',
13+
]);
14+
15+
// register a single rule
16+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
17+
18+
// define sets of rules
19+
$rectorConfig->sets([
20+
LevelSetList::UP_TO_PHP_80,
21+
]);
22+
};

src/EmailTarget.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,13 @@
2121
*/
2222
final class EmailTarget extends Target
2323
{
24-
/**
25-
* @var MailerInterface The mailer instance.
26-
*/
27-
private MailerInterface $mailer;
28-
2924
/**
3025
* @var array|string The receiver email address.
3126
* @psalm-var array<array-key, string>|string
3227
* You may pass an array of addresses if multiple recipients should receive this message.
3328
* You may also specify receiver name in addition to email address using format: `[email => name]`.
3429
*/
35-
private $emailTo;
30+
private array|string $emailTo;
3631

3732
/**
3833
* @var string The email message subject.
@@ -52,14 +47,12 @@ final class EmailTarget extends Target
5247
*
5348
* @psalm-suppress DocblockTypeContradiction
5449
*/
55-
public function __construct(MailerInterface $mailer, $emailTo, string $subjectEmail = '')
50+
public function __construct(private MailerInterface $mailer, $emailTo, string $subjectEmail = '')
5651
{
5752
/** @psalm-suppress TypeDoesNotContainType */
5853
if (empty($emailTo) || (!is_string($emailTo) && !is_array($emailTo))) {
5954
throw new InvalidArgumentException('The "to" argument must be an array or string and must not be empty.');
6055
}
61-
62-
$this->mailer = $mailer;
6356
$this->emailTo = $emailTo;
6457
$this->subjectEmail = $subjectEmail ?: 'Application Log';
6558
parent::__construct();

tests/EmailTargetTest.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use InvalidArgumentException;
88
use PHPUnit\Framework\TestCase;
9-
use PHPUnit\Framework\MockObject\MockObject;
109
use Psr\Log\LogLevel;
1110
use ReflectionException;
1211
use ReflectionObject;
@@ -21,15 +20,9 @@
2120

2221
final class EmailTargetTest extends TestCase
2322
{
24-
/**
25-
* @var Mailer|MockObject
26-
*/
27-
private $mailer;
23+
private \Yiisoft\Mailer\Mailer|\PHPUnit\Framework\MockObject\MockObject $mailer;
2824

29-
/**
30-
* @var MessageInterface|MockObject
31-
*/
32-
private $message;
25+
private \Yiisoft\Mailer\MessageInterface|\PHPUnit\Framework\MockObject\MockObject $message;
3326

3427
/**
3528
* Set up mailer.
@@ -180,24 +173,16 @@ public function invalidEmailToDataProvider(): array
180173

181174
/**
182175
* @dataProvider invalidEmailToDataProvider
183-
*
184-
* @param mixed $emailTo
185176
*/
186-
public function testConstructThrownExceptionForInvalidEmailTo($emailTo): void
177+
public function testConstructThrownExceptionForInvalidEmailTo(mixed $emailTo): void
187178
{
188179
$this->expectException(InvalidArgumentException::class);
189180
$this->expectExceptionMessage('The "to" argument must be an array or string and must not be empty.');
190181

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

194-
/**
195-
* @param mixed $emailTo
196-
* @param string $subjectEmail
197-
*
198-
* @return EmailTarget
199-
*/
200-
private function createEmailTarget($emailTo, string $subjectEmail = ''): EmailTarget
185+
private function createEmailTarget(mixed $emailTo, string $subjectEmail = ''): EmailTarget
201186
{
202187
$target = new EmailTarget($this->mailer, $emailTo, $subjectEmail);
203188
$target->setFormat(fn (Message $message) => "[{$message->level()}] {$message->message()}");
@@ -207,11 +192,7 @@ private function createEmailTarget($emailTo, string $subjectEmail = ''): EmailTa
207192
/**
208193
* Invokes the `EmailTarget::formatMessages()` protected method.
209194
*
210-
* @param EmailTarget $target
211-
*
212195
* @throws ReflectionException
213-
*
214-
* @return string
215196
*/
216197
private function invokeFormatMessagesMethod(EmailTarget $target): string
217198
{

0 commit comments

Comments
 (0)