Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rector Config & Apply some rules #84

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-mockery": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1",
"phpunit/phpunit": "^11"
"phpunit/phpunit": "^11",
"rector/rector": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -47,6 +48,7 @@
},
"scripts": {
"qa": [
"@composer rector:dry-run",
"@composer check-cs",
"@composer stan",
"@composer tests"
Expand All @@ -55,7 +57,9 @@
"tests": "phpunit -c phpunit.xml.dist",
"stan": "phpstan",
"check-cs": "php-cs-fixer fix --dry-run --diff",
"fix-cs": "php-cs-fixer fix"
"fix-cs": "php-cs-fixer fix",
"rector:dry-run": ["rector process -n"],
"rector:fix": ["rector process"]
},
"config": {
"sort-packages": true,
Expand Down
58 changes: 57 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector;
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPreparedSets(deadCode: true, codeQuality: true)
->withRules([
AddLiteralSeparatorToNumberRector::class,
ClosureToArrowFunctionRector::class,
AssertSameTrueFalseToAssertTrueFalseRector::class,
StaticDataProviderClassMethodRector::class,
AddVoidReturnTypeWhereNoReturnRector::class,
]);
6 changes: 3 additions & 3 deletions src/Handler/DeeplBatchTranslationRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public function getBody(): StreamInterface
[
'target_lang' => $this->translation->getTargetLang(),
'tag_handling' => implode(
static::SEPARATOR,
self::SEPARATOR,
$this->translation->getTagHandling()
),
'non_splitting_tags' => implode(
static::SEPARATOR,
self::SEPARATOR,
$this->translation->getNonSplittingTags()
),
'ignore_tags' => implode(static::SEPARATOR, $this->translation->getIgnoreTags()),
'ignore_tags' => implode(self::SEPARATOR, $this->translation->getIgnoreTags()),
'split_sentences' => $this->translation->getSplitSentences(),
'preserve_formatting' => $this->translation->getPreserveFormatting(),
'glossary_id' => $this->translation->getGlossaryId(),
Expand Down
6 changes: 3 additions & 3 deletions src/Handler/DeeplTranslationRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public function getBody(): StreamInterface
'target_lang' => $this->translation->getTargetLang(),
'source_lang' => $this->translation->getSourceLang(),
'tag_handling' => implode(
static::SEPARATOR,
self::SEPARATOR,
$this->translation->getTagHandling()
),
'non_splitting_tags' => implode(
static::SEPARATOR,
self::SEPARATOR,
$this->translation->getNonSplittingTags()
),
'ignore_tags' => implode(static::SEPARATOR, $this->translation->getIgnoreTags()),
'ignore_tags' => implode(self::SEPARATOR, $this->translation->getIgnoreTags()),
'split_sentences' => $this->translation->getSplitSentences(),
'preserve_formatting' => $this->translation->getPreserveFormatting(),
'glossary_id' => $this->translation->getGlossaryId(),
Expand Down
24 changes: 9 additions & 15 deletions tests/DeeplClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,20 @@ public function testCreateReturnsClientWithCustomLibraries(): void

$authKey = 'some-auth-key';

$this->assertInstanceOf(
DeeplClientInterface::class,
DeeplClientFactory::create(
$authKey,
$client,
$requestFactory,
$streamFactory
)
);
self::assertInstanceOf(DeeplClientInterface::class, DeeplClientFactory::create(
$authKey,
$client,
$requestFactory,
$streamFactory
));
}

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

$this->assertInstanceOf(
DeeplClientInterface::class,
DeeplClientFactory::create(
$authKey
)
);
self::assertInstanceOf(DeeplClientInterface::class, DeeplClientFactory::create(
$authKey
));
}
}
31 changes: 14 additions & 17 deletions tests/DeeplClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testGetUsageCanReturnUsageModel(): void
->with($request)
->willReturn($response);

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

public function testGetTranslationCanThrowException(): void
Expand Down Expand Up @@ -193,7 +193,7 @@ public function testGetTranslationCanReturnTranslationModel(): void
->with($request)
->willReturn($response);

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

public function testTranslateCanReturnJsonEncodedObject(): void
Expand Down Expand Up @@ -234,7 +234,7 @@ public function testTranslateCanReturnJsonEncodedObject(): void
->with($request)
->willReturn($response);

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

public function testTranslateBatchPerformsBatchTranslations(): void
Expand Down Expand Up @@ -274,10 +274,7 @@ public function testTranslateBatchPerformsBatchTranslations(): void
->with($request)
->willReturn($response);

$this->assertInstanceOf(
BatchTranslationInterface::class,
$this->subject->translateBatch(['some text'], 'some language')
);
self::assertInstanceOf(BatchTranslationInterface::class, $this->subject->translateBatch(['some text'], 'some language'));
}

public function testTranslateFileCanReturnInstanceOfResponseModel(): void
Expand Down Expand Up @@ -320,7 +317,7 @@ public function testTranslateFileCanReturnInstanceOfResponseModel(): void
->with($request)
->willReturn($response);

$this->assertInstanceOf(FileSubmissionInterface::class, $this->subject->translateFile($fileTranslation));
self::assertInstanceOf(FileSubmissionInterface::class, $this->subject->translateFile($fileTranslation));
}

public function testGetFileTranslationStatusCanReturnInstanceOfResponseModel(): void
Expand Down Expand Up @@ -363,7 +360,7 @@ public function testGetFileTranslationStatusCanReturnInstanceOfResponseModel():
->with($request)
->willReturn($response);

$this->assertInstanceOf(FileTranslationStatusInterface::class, $this->subject->getFileTranslationStatus($fileSubmission));
self::assertInstanceOf(FileTranslationStatusInterface::class, $this->subject->getFileTranslationStatus($fileSubmission));
}

public function testGetFileTranslationCanReturnInstanceOfResponseModel(): void
Expand Down Expand Up @@ -402,7 +399,7 @@ public function testGetFileTranslationCanReturnInstanceOfResponseModel(): void
->with($request)
->willReturn($response);

$this->assertInstanceOf(FileTranslationInterface::class, $this->subject->getFileTranslation($fileSubmission));
self::assertInstanceOf(FileTranslationInterface::class, $this->subject->getFileTranslation($fileSubmission));
}

public static function errorStatusCodeProvider(): array
Expand Down Expand Up @@ -487,7 +484,7 @@ public function testGetSupportedLanguagesReturnsSupportedLanguagesModel(): void
->with($request)
->willReturn($response);

$this->assertInstanceOf(SupportedLanguages::class, $this->subject->getSupportedLanguages());
self::assertInstanceOf(SupportedLanguages::class, $this->subject->getSupportedLanguages());
}

public function testGetGlossariesSupportedLanguagesPairsGetCorrectModel(): void
Expand Down Expand Up @@ -528,7 +525,7 @@ public function testGetGlossariesSupportedLanguagesPairsGetCorrectModel(): void
->with($request)
->willReturn($response);

$this->assertInstanceOf(GlossariesSupportedLanguagesPairs::class, $this->subject->getGlossariesSupportedLanguagesPairs());
self::assertInstanceOf(GlossariesSupportedLanguagesPairs::class, $this->subject->getGlossariesSupportedLanguagesPairs());
}

public function testGetGlossariesListGetCorrectModel(): void
Expand Down Expand Up @@ -569,7 +566,7 @@ public function testGetGlossariesListGetCorrectModel(): void
->with($request)
->willReturn($response);

$this->assertInstanceOf(Glossaries::class, $this->subject->getGlossariesList());
self::assertInstanceOf(Glossaries::class, $this->subject->getGlossariesList());
}

public function testCreateGlossaryGetCorrectModel(): void
Expand Down Expand Up @@ -612,7 +609,7 @@ public function testCreateGlossaryGetCorrectModel(): void

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

$this->assertInstanceOf(Glossary::class, $this->subject->createGlossary($submission));
self::assertInstanceOf(Glossary::class, $this->subject->createGlossary($submission));
}

public function testRetrieveGlossaryGetCorrectModel(): void
Expand Down Expand Up @@ -654,7 +651,7 @@ public function testRetrieveGlossaryGetCorrectModel(): void
->willReturn($response);

$submission = $this->createMock(GlossaryIdSubmission::class);
$this->assertInstanceOf(Glossary::class, $this->subject->retrieveGlossary($submission));
self::assertInstanceOf(Glossary::class, $this->subject->retrieveGlossary($submission));
}

public function testDeleteGlossaryGetCorrectBoolean(): void
Expand Down Expand Up @@ -696,7 +693,7 @@ public function testDeleteGlossaryGetCorrectBoolean(): void
->willReturn($response);

$submission = $this->createMock(GlossaryIdSubmission::class);
$this->assertTrue($this->subject->deleteGlossary($submission));
self::assertTrue($this->subject->deleteGlossary($submission));
}

public function testRetrieveGlossaryEntriesGetCorrectModel(): void
Expand Down Expand Up @@ -738,7 +735,7 @@ public function testRetrieveGlossaryEntriesGetCorrectModel(): void
->willReturn($response);

$submission = $this->createMock(GlossaryIdSubmission::class);
$this->assertInstanceOf(GlossaryEntries::class, $this->subject->retrieveGlossaryEntries($submission));
self::assertInstanceOf(GlossaryEntries::class, $this->subject->retrieveGlossaryEntries($submission));
}

private function createRequestExpectations(
Expand Down
14 changes: 4 additions & 10 deletions tests/Handler/DeeplFileRequestHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testGetPathCanReturnPath(): void
$this->fileSubmission->expects($this->once())
->method('getDocumentId')
->willReturn('documentId');
$this->assertSame(sprintf(DeeplFileRequestHandler::API_ENDPOINT, 'documentId'), $this->subject->getPath());
self::assertSame(sprintf(DeeplFileRequestHandler::API_ENDPOINT, 'documentId'), $this->subject->getPath());
}

public function testGetBodyCanReturnFilteredArray(): void
Expand All @@ -65,22 +65,16 @@ public function testGetBodyCanReturnFilteredArray(): void
)
->willReturn($stream);

$this->assertSame(
$stream,
$this->subject->getBody()
);
self::assertSame($stream, $this->subject->getBody());
}

public function testGetMethodCanReturnMethod(): void
{
$this->assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod());
self::assertSame(DeeplRequestHandlerInterface::METHOD_POST, $this->subject->getMethod());
}

public function testGetContentTypeReturnsValue(): void
{
$this->assertSame(
'application/x-www-form-urlencoded',
$this->subject->getContentType()
);
self::assertSame('application/x-www-form-urlencoded', $this->subject->getContentType());
}
}
Loading
Loading