Skip to content

Commit

Permalink
Add rector [batch] (#32)
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

* Update tests/Support/Psr7WorkerMock.php

* Skip closure to arrow function rule

* Add previous missing changes from rector

Co-authored-by: rector-bot <rector@yiiframework.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Alexey Rogachev <arogachev90@gmail.com>
  • Loading branch information
4 people committed Sep 29, 2022
1 parent 811acd3 commit c1474d7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 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 @@ -42,6 +42,7 @@
"require-dev": {
"httpsoft/http-message": "^1.0",
"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
27 changes: 27 additions & 0 deletions rector.php
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
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,
]);

$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
]);
};
4 changes: 0 additions & 4 deletions src/RoadRunnerApplicationRunner.php
Expand Up @@ -53,8 +53,6 @@ public function __construct(string $rootPath, bool $debug, ?string $environment)
* then the error handler configured in your application configuration will be used.
*
* @param ErrorHandler $temporaryErrorHandler The temporary error handler instance.
*
* @return self
*/
public function withTemporaryErrorHandler(ErrorHandler $temporaryErrorHandler): self
{
Expand All @@ -67,8 +65,6 @@ public function withTemporaryErrorHandler(ErrorHandler $temporaryErrorHandler):
* Returns a new instance with the specified PSR-7 worker instance {@see PSR7WorkerInterface}.
*
* @param PSR7WorkerInterface $worker The PSR-7 worker instance.
*
* @return self
*/
public function withPsr7Worker(PSR7WorkerInterface $worker): self
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/PlainTextRendererMock.php
Expand Up @@ -25,6 +25,6 @@ public function renderVerbose(Throwable $t, ServerRequestInterface $request = nu
'request-method' => (string) $request?->getMethod(),
'request-uri' => (string) $request?->getUri(),
'request-attribute-exists' => (bool) $request?->getAttribute('applicationStartTime'),
]));
], JSON_THROW_ON_ERROR));
}
}
6 changes: 2 additions & 4 deletions tests/Support/Psr7WorkerMock.php
Expand Up @@ -15,12 +15,10 @@

final class Psr7WorkerMock implements PSR7WorkerInterface
{
private ServerRequestInterface|Throwable|null $request;
private int $requestCount = 0;

public function __construct(ServerRequestInterface|Throwable $request = null)
public function __construct(private ServerRequestInterface|Throwable|null $request = null)
{
$this->request = $request;
}

public function getRequestCount(): int
Expand All @@ -47,7 +45,7 @@ public function respond(ResponseInterface $response): void
'status' => $response->getStatusCode(),
'headers' => $response->getHeaders(),
'body' => (string) $response->getBody(),
]);
], JSON_THROW_ON_ERROR);
}

public function getWorker(): WorkerInterface
Expand Down
7 changes: 2 additions & 5 deletions tests/TestCase.php
Expand Up @@ -77,11 +77,8 @@ static function (ContainerInterface $container) use ($throwException) {
->get(MiddlewareDispatcher::class)
->withMiddlewares([
static fn () => new class ($throwException) implements MiddlewareInterface {
private bool $throwException;

public function __construct(bool $throwException)
public function __construct(private bool $throwException)
{
$this->throwException = $throwException;
}

public function process(
Expand Down Expand Up @@ -120,6 +117,6 @@ protected function getResponseData(int $status = Status::OK, array $headers = []
'status' => $status,
'headers' => $headers,
'body' => $body,
]);
], JSON_THROW_ON_ERROR);
}
}

0 comments on commit c1474d7

Please sign in to comment.