Skip to content

Commit 2cd169c

Browse files
WorksDevusox
authored andcommitted
Add Rector Config & Apply some rules
1 parent 2cc93c9 commit 2cd169c

24 files changed

+196
-250
lines changed

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"phpstan/phpstan": "^1.4",
3434
"phpstan/phpstan-mockery": "^1.0",
3535
"phpstan/phpstan-strict-rules": "^1.1",
36-
"phpunit/phpunit": "^11"
36+
"phpunit/phpunit": "^11",
37+
"rector/rector": "^1.0"
3738
},
3839
"autoload": {
3940
"psr-4": {
@@ -47,6 +48,7 @@
4748
},
4849
"scripts": {
4950
"qa": [
51+
"@composer rector:dry-run",
5052
"@composer check-cs",
5153
"@composer stan",
5254
"@composer tests"
@@ -55,7 +57,9 @@
5557
"tests": "phpunit -c phpunit.xml.dist",
5658
"stan": "phpstan",
5759
"check-cs": "php-cs-fixer fix --dry-run --diff",
58-
"fix-cs": "php-cs-fixer fix"
60+
"fix-cs": "php-cs-fixer fix",
61+
"rector:dry-run": ["rector process -n"],
62+
"rector:fix": ["rector process"]
5963
},
6064
"config": {
6165
"sort-packages": true,

composer.lock

Lines changed: 57 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rector.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
7+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
8+
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
9+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector;
10+
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
11+
12+
return RectorConfig::configure()
13+
->withPaths([
14+
__DIR__ . '/src',
15+
__DIR__ . '/tests',
16+
])
17+
->withPreparedSets(deadCode: true, codeQuality: true)
18+
->withRules([
19+
AddLiteralSeparatorToNumberRector::class,
20+
ClosureToArrowFunctionRector::class,
21+
AssertSameTrueFalseToAssertTrueFalseRector::class,
22+
StaticDataProviderClassMethodRector::class,
23+
AddVoidReturnTypeWhereNoReturnRector::class,
24+
]);

src/Handler/DeeplBatchTranslationRequestHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public function getBody(): StreamInterface
4949
[
5050
'target_lang' => $this->translation->getTargetLang(),
5151
'tag_handling' => implode(
52-
static::SEPARATOR,
52+
self::SEPARATOR,
5353
$this->translation->getTagHandling()
5454
),
5555
'non_splitting_tags' => implode(
56-
static::SEPARATOR,
56+
self::SEPARATOR,
5757
$this->translation->getNonSplittingTags()
5858
),
59-
'ignore_tags' => implode(static::SEPARATOR, $this->translation->getIgnoreTags()),
59+
'ignore_tags' => implode(self::SEPARATOR, $this->translation->getIgnoreTags()),
6060
'split_sentences' => $this->translation->getSplitSentences(),
6161
'preserve_formatting' => $this->translation->getPreserveFormatting(),
6262
'glossary_id' => $this->translation->getGlossaryId(),

src/Handler/DeeplTranslationRequestHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public function getBody(): StreamInterface
4949
'target_lang' => $this->translation->getTargetLang(),
5050
'source_lang' => $this->translation->getSourceLang(),
5151
'tag_handling' => implode(
52-
static::SEPARATOR,
52+
self::SEPARATOR,
5353
$this->translation->getTagHandling()
5454
),
5555
'non_splitting_tags' => implode(
56-
static::SEPARATOR,
56+
self::SEPARATOR,
5757
$this->translation->getNonSplittingTags()
5858
),
59-
'ignore_tags' => implode(static::SEPARATOR, $this->translation->getIgnoreTags()),
59+
'ignore_tags' => implode(self::SEPARATOR, $this->translation->getIgnoreTags()),
6060
'split_sentences' => $this->translation->getSplitSentences(),
6161
'preserve_formatting' => $this->translation->getPreserveFormatting(),
6262
'glossary_id' => $this->translation->getGlossaryId(),

tests/DeeplClientFactoryTest.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,20 @@ public function testCreateReturnsClientWithCustomLibraries(): void
1818

1919
$authKey = 'some-auth-key';
2020

21-
$this->assertInstanceOf(
22-
DeeplClientInterface::class,
23-
DeeplClientFactory::create(
24-
$authKey,
25-
$client,
26-
$requestFactory,
27-
$streamFactory
28-
)
29-
);
21+
self::assertInstanceOf(DeeplClientInterface::class, DeeplClientFactory::create(
22+
$authKey,
23+
$client,
24+
$requestFactory,
25+
$streamFactory
26+
));
3027
}
3128

3229
public function testCreateReturnsClientWithAutoDisovery(): void
3330
{
3431
$authKey = 'some-auth-key';
3532

36-
$this->assertInstanceOf(
37-
DeeplClientInterface::class,
38-
DeeplClientFactory::create(
39-
$authKey
40-
)
41-
);
33+
self::assertInstanceOf(DeeplClientInterface::class, DeeplClientFactory::create(
34+
$authKey
35+
));
4236
}
4337
}

tests/DeeplClientTest.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testGetUsageCanReturnUsageModel(): void
120120
->with($request)
121121
->willReturn($response);
122122

123-
$this->assertInstanceOf(UsageInterface::class, $this->subject->getUsage());
123+
self::assertInstanceOf(UsageInterface::class, $this->subject->getUsage());
124124
}
125125

126126
public function testGetTranslationCanThrowException(): void
@@ -193,7 +193,7 @@ public function testGetTranslationCanReturnTranslationModel(): void
193193
->with($request)
194194
->willReturn($response);
195195

196-
$this->assertInstanceOf(TranslationInterface::class, $this->subject->getTranslation($translation));
196+
self::assertInstanceOf(TranslationInterface::class, $this->subject->getTranslation($translation));
197197
}
198198

199199
public function testTranslateCanReturnJsonEncodedObject(): void
@@ -234,7 +234,7 @@ public function testTranslateCanReturnJsonEncodedObject(): void
234234
->with($request)
235235
->willReturn($response);
236236

237-
$this->assertInstanceOf(TranslationInterface::class, $this->subject->translate('some text', 'some language'));
237+
self::assertInstanceOf(TranslationInterface::class, $this->subject->translate('some text', 'some language'));
238238
}
239239

240240
public function testTranslateBatchPerformsBatchTranslations(): void
@@ -274,10 +274,7 @@ public function testTranslateBatchPerformsBatchTranslations(): void
274274
->with($request)
275275
->willReturn($response);
276276

277-
$this->assertInstanceOf(
278-
BatchTranslationInterface::class,
279-
$this->subject->translateBatch(['some text'], 'some language')
280-
);
277+
self::assertInstanceOf(BatchTranslationInterface::class, $this->subject->translateBatch(['some text'], 'some language'));
281278
}
282279

283280
public function testTranslateFileCanReturnInstanceOfResponseModel(): void
@@ -320,7 +317,7 @@ public function testTranslateFileCanReturnInstanceOfResponseModel(): void
320317
->with($request)
321318
->willReturn($response);
322319

323-
$this->assertInstanceOf(FileSubmissionInterface::class, $this->subject->translateFile($fileTranslation));
320+
self::assertInstanceOf(FileSubmissionInterface::class, $this->subject->translateFile($fileTranslation));
324321
}
325322

326323
public function testGetFileTranslationStatusCanReturnInstanceOfResponseModel(): void
@@ -363,7 +360,7 @@ public function testGetFileTranslationStatusCanReturnInstanceOfResponseModel():
363360
->with($request)
364361
->willReturn($response);
365362

366-
$this->assertInstanceOf(FileTranslationStatusInterface::class, $this->subject->getFileTranslationStatus($fileSubmission));
363+
self::assertInstanceOf(FileTranslationStatusInterface::class, $this->subject->getFileTranslationStatus($fileSubmission));
367364
}
368365

369366
public function testGetFileTranslationCanReturnInstanceOfResponseModel(): void
@@ -402,7 +399,7 @@ public function testGetFileTranslationCanReturnInstanceOfResponseModel(): void
402399
->with($request)
403400
->willReturn($response);
404401

405-
$this->assertInstanceOf(FileTranslationInterface::class, $this->subject->getFileTranslation($fileSubmission));
402+
self::assertInstanceOf(FileTranslationInterface::class, $this->subject->getFileTranslation($fileSubmission));
406403
}
407404

408405
public static function errorStatusCodeProvider(): array
@@ -487,7 +484,7 @@ public function testGetSupportedLanguagesReturnsSupportedLanguagesModel(): void
487484
->with($request)
488485
->willReturn($response);
489486

490-
$this->assertInstanceOf(SupportedLanguages::class, $this->subject->getSupportedLanguages());
487+
self::assertInstanceOf(SupportedLanguages::class, $this->subject->getSupportedLanguages());
491488
}
492489

493490
public function testGetGlossariesSupportedLanguagesPairsGetCorrectModel(): void
@@ -528,7 +525,7 @@ public function testGetGlossariesSupportedLanguagesPairsGetCorrectModel(): void
528525
->with($request)
529526
->willReturn($response);
530527

531-
$this->assertInstanceOf(GlossariesSupportedLanguagesPairs::class, $this->subject->getGlossariesSupportedLanguagesPairs());
528+
self::assertInstanceOf(GlossariesSupportedLanguagesPairs::class, $this->subject->getGlossariesSupportedLanguagesPairs());
532529
}
533530

534531
public function testGetGlossariesListGetCorrectModel(): void
@@ -569,7 +566,7 @@ public function testGetGlossariesListGetCorrectModel(): void
569566
->with($request)
570567
->willReturn($response);
571568

572-
$this->assertInstanceOf(Glossaries::class, $this->subject->getGlossariesList());
569+
self::assertInstanceOf(Glossaries::class, $this->subject->getGlossariesList());
573570
}
574571

575572
public function testCreateGlossaryGetCorrectModel(): void
@@ -612,7 +609,7 @@ public function testCreateGlossaryGetCorrectModel(): void
612609

613610
$submission = $this->createMock(GlossarySubmission::class);
614611

615-
$this->assertInstanceOf(Glossary::class, $this->subject->createGlossary($submission));
612+
self::assertInstanceOf(Glossary::class, $this->subject->createGlossary($submission));
616613
}
617614

618615
public function testRetrieveGlossaryGetCorrectModel(): void
@@ -654,7 +651,7 @@ public function testRetrieveGlossaryGetCorrectModel(): void
654651
->willReturn($response);
655652

656653
$submission = $this->createMock(GlossaryIdSubmission::class);
657-
$this->assertInstanceOf(Glossary::class, $this->subject->retrieveGlossary($submission));
654+
self::assertInstanceOf(Glossary::class, $this->subject->retrieveGlossary($submission));
658655
}
659656

660657
public function testDeleteGlossaryGetCorrectBoolean(): void
@@ -696,7 +693,7 @@ public function testDeleteGlossaryGetCorrectBoolean(): void
696693
->willReturn($response);
697694

698695
$submission = $this->createMock(GlossaryIdSubmission::class);
699-
$this->assertTrue($this->subject->deleteGlossary($submission));
696+
self::assertTrue($this->subject->deleteGlossary($submission));
700697
}
701698

702699
public function testRetrieveGlossaryEntriesGetCorrectModel(): void
@@ -738,7 +735,7 @@ public function testRetrieveGlossaryEntriesGetCorrectModel(): void
738735
->willReturn($response);
739736

740737
$submission = $this->createMock(GlossaryIdSubmission::class);
741-
$this->assertInstanceOf(GlossaryEntries::class, $this->subject->retrieveGlossaryEntries($submission));
738+
self::assertInstanceOf(GlossaryEntries::class, $this->subject->retrieveGlossaryEntries($submission));
742739
}
743740

744741
private function createRequestExpectations(

tests/Handler/DeeplFileRequestHandlerTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testGetPathCanReturnPath(): void
4242
$this->fileSubmission->expects($this->once())
4343
->method('getDocumentId')
4444
->willReturn('documentId');
45-
$this->assertSame(sprintf(DeeplFileRequestHandler::API_ENDPOINT, 'documentId'), $this->subject->getPath());
45+
self::assertSame(sprintf(DeeplFileRequestHandler::API_ENDPOINT, 'documentId'), $this->subject->getPath());
4646
}
4747

4848
public function testGetBodyCanReturnFilteredArray(): void
@@ -65,22 +65,16 @@ public function testGetBodyCanReturnFilteredArray(): void
6565
)
6666
->willReturn($stream);
6767

68-
$this->assertSame(
69-
$stream,
70-
$this->subject->getBody()
71-
);
68+
self::assertSame($stream, $this->subject->getBody());
7269
}
7370

7471
public function testGetMethodCanReturnMethod(): void
7572
{
76-
$this->assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod());
73+
self::assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod());
7774
}
7875

7976
public function testGetContentTypeReturnsValue(): void
8077
{
81-
$this->assertSame(
82-
'application/x-www-form-urlencoded',
83-
$this->subject->getContentType()
84-
);
78+
self::assertSame('application/x-www-form-urlencoded', $this->subject->getContentType());
8579
}
8680
}

0 commit comments

Comments
 (0)