Skip to content

Commit

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

* Use predefined rector action

* Update src/Middleware/SwaggerJson.php

* Apply fixes from StyleCI

* Update src/Middleware/SwaggerUi.php

* Apply fixes from StyleCI

Co-authored-by: rector-bot <rector@yiiframework.com>
Co-authored-by: Alexey Rogachev <arogachev90@gmail.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
4 people committed Sep 29, 2022
1 parent 8124c91 commit ed94cbc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 36 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 @@ -40,6 +40,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
22 changes: 22 additions & 0 deletions rector.php
@@ -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,
]);
};
19 changes: 3 additions & 16 deletions src/Middleware/SwaggerJson.php
Expand Up @@ -18,19 +18,13 @@ final class SwaggerJson implements MiddlewareInterface
{
private array $annotationPaths = [];
private bool $enableCache = false;
private CacheInterface $cache;
private DataResponseFactoryInterface $responseFactory;
private SwaggerService $swaggerService;
private DateInterval|int|null $cacheTTL = null;

public function __construct(
CacheInterface $cache,
DataResponseFactoryInterface $responseFactory,
SwaggerService $swaggerService
private CacheInterface $cache,
private DataResponseFactoryInterface $responseFactory,
private SwaggerService $swaggerService
) {
$this->cache = $cache;
$this->responseFactory = $responseFactory;
$this->swaggerService = $swaggerService;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
Expand All @@ -45,11 +39,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $this->responseFactory->createResponse($openApi);
}

/**
* @param string ...$annotationPaths
*
* @return self
*/
public function withAnnotationPaths(string ...$annotationPaths): self
{
$new = clone $this;
Expand All @@ -59,8 +48,6 @@ public function withAnnotationPaths(string ...$annotationPaths): self

/**
* @param DateInterval|int|null $cacheTTL
*
* @return self
*/
public function withCache(DateInterval|int $cacheTTL = null): self
{
Expand Down
16 changes: 4 additions & 12 deletions src/Middleware/SwaggerUi.php
Expand Up @@ -28,21 +28,13 @@ final class SwaggerUi implements MiddlewareInterface
'layout' => 'StandaloneLayout',
];
private string $jsonUrl = '/';
private SwaggerService $swaggerService;
private ViewRenderer $viewRenderer;
private AssetManager $assetManager;
private array $params;

public function __construct(
ViewRenderer $viewRenderer,
SwaggerService $swaggerService,
AssetManager $assetManager,
array $params
private ViewRenderer $viewRenderer,
private SwaggerService $swaggerService,
private AssetManager $assetManager,
private array $params
) {
$this->swaggerService = $swaggerService;
$this->viewRenderer = $viewRenderer;
$this->assetManager = $assetManager;
$this->params = $params;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
Expand Down
10 changes: 2 additions & 8 deletions src/Service/SwaggerService.php
Expand Up @@ -18,17 +18,13 @@

final class SwaggerService
{
private Aliases $aliases;

private string $viewPath;
private string $viewName;
private string $viewName = 'swagger-ui';
private array $options = [];

public function __construct(Aliases $aliases)
public function __construct(private Aliases $aliases)
{
$this->aliases = $aliases;
$this->viewPath = dirname(__DIR__, 2) . '/views';
$this->viewName = 'swagger-ui';
}

public function getViewPath(): string
Expand All @@ -45,8 +41,6 @@ public function getViewName(): string
* Returns a new instance with the specified options for {@see OpenApi} generation.
*
* @param array $options For {@see Generator::scan()}.
*
* @return self
*/
public function withOptions(array $options): self
{
Expand Down

0 comments on commit ed94cbc

Please sign in to comment.