Skip to content

Commit

Permalink
Add rector [batch] (#17)
Browse files Browse the repository at this point in the history
* Add rector files yiisoft/yii-dev-tool#232

* Add rector/rector dependecy

* [rector] Apply fixes

* Apply fixes from StyleCI

* Use predefined rector action

* fix

* fix

Co-authored-by: rector-bot <rector@yiiframework.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
  • Loading branch information
4 people authored Dec 28, 2022
1 parent 6e5fb61 commit d44fd73
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 54 deletions.
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']
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"require-dev": {
"phpunit/phpunit": "^9.5",
"roave/infection-static-analysis-plugin": "^1.25",
"rector/rector": "^0.15.2",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.4",
"yiisoft/files": "^2.0",
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,
]);
};
14 changes: 3 additions & 11 deletions src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Yiisoft\Mailer\MessageFactoryInterface;
use Yiisoft\Mailer\MessageInterface;

use function get_class;
use function sprintf;

/**
Expand All @@ -30,10 +29,7 @@ final class Mailer extends BaseMailer
private SymfonyMailer $symfonyMailer;
private ?SMimeEncrypter $encryptor = null;

/**
* @var DkimSigner|SMimeSigner|null
*/
private $signer = null;
private null|DkimSigner|SMimeSigner $signer = null;
private array $dkimSignerOptions = [];

/**
Expand All @@ -58,8 +54,6 @@ public function __construct(
* @param SMimeEncrypter $encryptor The encryptor instance.
*
* @see https://symfony.com/doc/current/mailer.html#encrypting-messages
*
* @return self
*/
public function withEncryptor(SMimeEncrypter $encryptor): self
{
Expand All @@ -77,8 +71,6 @@ public function withEncryptor(SMimeEncrypter $encryptor): self
* @throws RuntimeException If the signer is not an instance of {@see DkimSigner} or {@see SMimeSigner}.
*
* @see https://symfony.com/doc/current/mailer.html#signing-messages
*
* @return self
*/
public function withSigner(object $signer, array $options = []): self
{
Expand All @@ -99,7 +91,7 @@ public function withSigner(object $signer, array $options = []): self
'The signer must be an instance of "%s" or "%s". The "%s" instance is received.',
DkimSigner::class,
SMimeSigner::class,
get_class($signer),
$signer::class,
));
}

Expand All @@ -114,7 +106,7 @@ protected function sendMessage(MessageInterface $message): void
throw new RuntimeException(sprintf(
'The message must be an instance of "%s". The "%s" instance is received.',
Message::class,
get_class($message),
$message::class,
));
}

Expand Down
7 changes: 4 additions & 3 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTimeImmutable;
use DateTimeInterface;
use Stringable;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Header\HeaderInterface;
Expand All @@ -21,7 +22,7 @@
* @see https://symfony.com/doc/current/mailer.html#creating-sending-messages
* @see Mailer
*/
final class Message implements MessageInterface
final class Message implements MessageInterface, Stringable
{
private Email $email;
private ?Throwable $error = null;
Expand Down Expand Up @@ -307,7 +308,7 @@ public function getSymfonyEmail(): Email
*
* @return array<string, string>|string
*/
private function convertAddressesToStrings(array $addresses)
private function convertAddressesToStrings(array $addresses): array|string
{
$strings = [];

Expand All @@ -325,7 +326,7 @@ private function convertAddressesToStrings(array $addresses)
*
* @return Address[]
*/
private function convertStringsToAddresses($strings): array
private function convertStringsToAddresses(array|string $strings): array
{
if (is_string($strings)) {
return [new Address($strings)];
Expand Down
3 changes: 1 addition & 2 deletions tests/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use function file_exists;
use function file_get_contents;
use function file_put_contents;
use function get_class;
use function openssl_pkcs7_decrypt;
use function sprintf;
use function str_replace;
Expand Down Expand Up @@ -80,7 +79,7 @@ public function testSendFailureForMessageIsNotSymfonyMessageInstance(): void
$this->expectExceptionMessage(sprintf(
'The message must be an instance of "%s". The "%s" instance is received.',
Message::class,
get_class($mock),
$mock::class,
));

$mailer->send($mock);
Expand Down
41 changes: 7 additions & 34 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public function charsetDataProvider(): array

/**
* @dataProvider charsetDataProvider
*
* @param string $charset
*/
public function testCharset(string $charset): void
{
Expand Down Expand Up @@ -81,11 +79,8 @@ public function addressesDataProvider(): array

/**
* @dataProvider addressesDataProvider
*
* @param array|string $from
* @param array $expected
*/
public function testFrom($from, array $expected): void
public function testFrom(array|string $from, array $expected): void
{
$message = $this->message->withFrom($from);

Expand All @@ -95,11 +90,8 @@ public function testFrom($from, array $expected): void

/**
* @dataProvider addressesDataProvider
*
* @param array|string $to
* @param array $expected
*/
public function testTo($to, array $expected): void
public function testTo(array|string $to, array $expected): void
{
$message = $this->message->withTo($to);

Expand All @@ -109,11 +101,8 @@ public function testTo($to, array $expected): void

/**
* @dataProvider addressesDataProvider
*
* @param array|string $replyTo
* @param array $expected
*/
public function testReplyTo($replyTo, array $expected): void
public function testReplyTo(array|string $replyTo, array $expected): void
{
$message = $this->message->withReplyTo($replyTo);

Expand All @@ -123,11 +112,8 @@ public function testReplyTo($replyTo, array $expected): void

/**
* @dataProvider addressesDataProvider
*
* @param array|string $cc
* @param array $expected
*/
public function testCc($cc, array $expected): void
public function testCc(array|string $cc, array $expected): void
{
$message = $this->message->withCc($cc);

Expand All @@ -137,11 +123,8 @@ public function testCc($cc, array $expected): void

/**
* @dataProvider addressesDataProvider
*
* @param array|string $bcc
* @param array $expected
*/
public function testBcc($bcc, array $expected): void
public function testBcc(array|string $bcc, array $expected): void
{
$message = $this->message->withBcc($bcc);

Expand Down Expand Up @@ -175,8 +158,6 @@ public function priorityDataProvider(): array

/**
* @dataProvider priorityDataProvider
*
* @param int $priority
*/
public function testPriority(int $priority): void
{
Expand Down Expand Up @@ -214,12 +195,8 @@ public function headerDataProvider(): array

/**
* @dataProvider headerDataProvider
*
* @param string $name
* @param array|string $value
* @param array $expected
*/
public function testHeader(string $name, $value, array $expected): void
public function testHeader(string $name, array|string $value, array $expected): void
{
$message = $this->message->withHeader($name, $value);

Expand All @@ -229,12 +206,8 @@ public function testHeader(string $name, $value, array $expected): void

/**
* @dataProvider headerDataProvider
*
* @param string $name
* @param array|string $value
* @param array $expected
*/
public function testHeaders(string $name, $value, array $expected): void
public function testHeaders(string $name, array|string $value, array $expected): void
{
$message = $this->message->withHeaders([$name => $value]);

Expand Down
3 changes: 2 additions & 1 deletion tests/TestAsset/DummyTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Yiisoft\Mailer\Symfony\Tests\TestAsset;

use Stringable;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\Exception\TransportException;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\RawMessage;

final class DummyTransport implements TransportInterface
final class DummyTransport implements TransportInterface, Stringable
{
/**
* @var RawMessage[]
Expand Down
3 changes: 0 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ protected function getTestFilePath(): string
/**
* Gets an inaccessible object property.
*
* @param object $object
* @param string $propertyName
*
* @return mixed
*/
protected function getInaccessibleProperty(object $object, string $propertyName)
Expand Down

0 comments on commit d44fd73

Please sign in to comment.