Skip to content

Commit b16c84a

Browse files
committed
fix(cs): fix .php-cs-fixer config include paths
1 parent 80c3543 commit b16c84a

34 files changed

Lines changed: 271 additions & 286 deletions

.php-cs-fixer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
$finder = PhpCsFixer\Finder::create()
77
->in(
88
[
9+
__DIR__ . '/src',
10+
__DIR__ . '/bin',
11+
__DIR__ . '/config',
912
__DIR__ . '/public',
1013
__DIR__ . '/tests',
1114
]

config/container.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
declare(strict_types=1);
33

4-
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddleware;
54
use Laminas\Diactoros\ResponseFactory;
65
use Laminas\Diactoros\StreamFactory;
76
use Laminas\ServiceManager\ServiceManager;
@@ -11,13 +10,14 @@
1110
use Mezzio\Router\FastRouteRouter;
1211
use Mezzio\Router\FastRouteRouter\ConfigProvider as FastRouteConfigProvider;
1312
use Mezzio\Router\RouterInterface;
13+
use Psr\Cache\CacheItemPoolInterface;
1414
use Psr\Http\Message\ResponseFactoryInterface;
1515
use Psr\Http\Message\ResponseInterface;
1616
use Psr\Http\Message\StreamFactoryInterface;
1717
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
18-
use Psr\Cache\CacheItemPoolInterface;
1918
use WebProject\PhpOpenApiMockServer\Factory\OpenApiMockMiddlewareFactory;
2019
use WebProject\PhpOpenApiMockServer\Middleware\ForceMockActiveMiddleware;
20+
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddleware;
2121

2222
$container = new ServiceManager();
2323

@@ -38,16 +38,16 @@
3838
$container->setAlias(RouterInterface::class, FastRouteRouter::class);
3939

4040
// Factories
41-
$container->setFactory(ResponseInterface::class, static fn(): Closure => static fn(): ResponseInterface => (new ResponseFactory())->createResponse());
41+
$container->setFactory(ResponseInterface::class, static fn (): Closure => static fn (): ResponseInterface => (new ResponseFactory())->createResponse());
4242
$container->setService(ResponseFactoryInterface::class, new ResponseFactory());
4343
$container->setService(StreamFactoryInterface::class, new StreamFactory());
4444

4545
// Cache Configuration — isolated per process to avoid conflicts between parallel server instances
4646
$processCacheDir = sys_get_temp_dir() . '/openapi_mock_cache/' . getmypid();
47-
$container->setFactory(CacheItemPoolInterface::class, static fn(): FilesystemAdapter => new FilesystemAdapter('openapi_mock', 0, $processCacheDir));
47+
$container->setFactory(CacheItemPoolInterface::class, static fn (): FilesystemAdapter => new FilesystemAdapter('openapi_mock', 0, $processCacheDir));
4848

4949
register_shutdown_function(static function () use ($processCacheDir): void {
50-
if (! is_dir($processCacheDir)) {
50+
if (!is_dir($processCacheDir)) {
5151
return;
5252
}
5353

config/pipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22
declare(strict_types=1);
33

4-
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddleware;
54
use Mezzio\Application;
65
use Mezzio\MiddlewareFactory;
76
use Mezzio\ProblemDetails\ProblemDetailsMiddleware;
87
use Mezzio\Router\Middleware\DispatchMiddleware;
98
use Mezzio\Router\Middleware\RouteMiddleware;
109
use WebProject\PhpOpenApiMockServer\Middleware\ForceMockActiveMiddleware;
10+
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddleware;
1111

1212
return static function (Application $application, MiddlewareFactory $middlewareFactory): void {
1313
// 1. Problem Details Catch-All

config/routes.php

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\Utils\RemoteSpecificationLoader;
1212

1313
return static function (Application $application, MiddlewareFactory $middlewareFactory): void {
14-
$specPath = getenv('OPENAPI_SPEC') ?: null;
14+
$specPath = getenv('OPENAPI_SPEC') ?: null;
1515
$packageRoot = realpath(__DIR__ . '/..') ?: '/app';
1616

17-
if ($specPath === null || $specPath === false) {
17+
if (null === $specPath || false === $specPath) {
1818
$specPath = $packageRoot . '/data/openapi.yaml';
1919
} elseif (!str_starts_with((string) $specPath, '/') && !str_starts_with((string) $specPath, 'http')) {
2020
$resolveBase = str_contains($packageRoot, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR)
@@ -33,7 +33,7 @@
3333
$content = file_exists($path) ? file_get_contents($path) : null;
3434
}
3535

36-
if ($content === false || $content === null) {
36+
if (false === $content || null === $content) {
3737
return new TextResponse('OpenAPI spec not found at ' . $path, 404);
3838
}
3939

@@ -67,50 +67,51 @@
6767
}
6868

6969
// Determine the correct spec URL for Swagger UI
70-
$path = (string) $specPath;
70+
$path = (string) $specPath;
7171
$parsedPath = parse_url($path, PHP_URL_PATH) ?: $path;
72-
$extension = strtolower(pathinfo($parsedPath, PATHINFO_EXTENSION));
73-
$specUrl = $extension === 'json' ? '/openapi.json' : '/openapi.yaml';
72+
$extension = strtolower(pathinfo($parsedPath, PATHINFO_EXTENSION));
73+
$specUrl = 'json' === $extension ? '/openapi.json' : '/openapi.yaml';
7474

7575
$html = <<<HTML
76-
<!DOCTYPE html>
77-
<html lang="en">
78-
<head>
79-
<meta charset="utf-8" />
80-
<meta name="viewport" content="width=device-width, initial-scale=1" />
81-
<meta name="description" content="SwaggerUI" />
82-
<title>OpenAPI Mock Server - Swagger UI</title>
83-
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css" />
84-
<style>
85-
html { box-sizing: border-box; overflow: -moz-scrollbars-vertical; overflow-y: scroll; }
86-
*, *:before, *:after { box-sizing: inherit; }
87-
body { margin: 0; background: #fafafa; }
88-
</style>
89-
</head>
90-
<body>
91-
<div id="swagger-ui"></div>
92-
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js" crossorigin></script>
93-
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js" crossorigin></script>
94-
<script>
95-
window.onload = () => {
96-
window.ui = SwaggerUIBundle({
97-
url: '$specUrl',
98-
dom_id: '#swagger-ui',
99-
deepLinking: true,
100-
presets: [
101-
SwaggerUIBundle.presets.apis,
102-
SwaggerUIStandalonePreset
103-
],
104-
plugins: [
105-
SwaggerUIBundle.plugins.DownloadUrl
106-
],
107-
layout: "BaseLayout",
108-
});
109-
};
110-
</script>
111-
</body>
112-
</html>
113-
HTML;
76+
<!DOCTYPE html>
77+
<html lang="en">
78+
<head>
79+
<meta charset="utf-8" />
80+
<meta name="viewport" content="width=device-width, initial-scale=1" />
81+
<meta name="description" content="SwaggerUI" />
82+
<title>OpenAPI Mock Server - Swagger UI</title>
83+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css" />
84+
<style>
85+
html { box-sizing: border-box; overflow: -moz-scrollbars-vertical; overflow-y: scroll; }
86+
*, *:before, *:after { box-sizing: inherit; }
87+
body { margin: 0; background: #fafafa; }
88+
</style>
89+
</head>
90+
<body>
91+
<div id="swagger-ui"></div>
92+
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js" crossorigin></script>
93+
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js" crossorigin></script>
94+
<script>
95+
window.onload = () => {
96+
window.ui = SwaggerUIBundle({
97+
url: '$specUrl',
98+
dom_id: '#swagger-ui',
99+
deepLinking: true,
100+
presets: [
101+
SwaggerUIBundle.presets.apis,
102+
SwaggerUIStandalonePreset
103+
],
104+
plugins: [
105+
SwaggerUIBundle.plugins.DownloadUrl
106+
],
107+
layout: "BaseLayout",
108+
});
109+
};
110+
</script>
111+
</body>
112+
</html>
113+
HTML;
114+
114115
return new HtmlResponse($html);
115116
}, 'home');
116117
};

src/Factory/OpenApiMockMiddlewareFactory.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
namespace WebProject\PhpOpenApiMockServer\Factory;
55

6-
use Psr\Cache\CacheItemPoolInterface;
7-
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddlewareBuilder;
8-
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddlewareConfig;
9-
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\Utils\RemoteSpecificationLoader;
6+
use const DIRECTORY_SEPARATOR;
7+
use function dirname;
8+
use function file_get_contents;
9+
use function getcwd;
10+
use function getenv;
1011
use Mezzio\ProblemDetails\ProblemDetailsResponseFactory;
12+
use Psr\Cache\CacheItemPoolInterface;
1113
use Psr\Container\ContainerInterface;
1214
use Psr\Http\Message\ResponseFactoryInterface;
1315
use Psr\Http\Message\ResponseInterface;
@@ -16,18 +18,14 @@
1618
use Psr\Http\Server\MiddlewareInterface;
1719
use Psr\Http\Server\RequestHandlerInterface;
1820
use RuntimeException;
19-
use Throwable;
20-
21-
use function dirname;
22-
use function file_get_contents;
23-
use function getcwd;
24-
use function getenv;
2521
use function sprintf;
2622
use function str_contains;
2723
use function str_ends_with;
2824
use function str_starts_with;
29-
30-
use const DIRECTORY_SEPARATOR;
25+
use Throwable;
26+
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddlewareBuilder;
27+
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddlewareConfig;
28+
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\Utils\RemoteSpecificationLoader;
3129

3230
class OpenApiMockMiddlewareFactory
3331
{
@@ -39,10 +37,10 @@ public function __invoke(ContainerInterface $container): MiddlewareInterface
3937
$mockConfig = (array) ($config['openapi_mock'] ?? []);
4038
$specPath = $mockConfig['spec'] ?? getenv('OPENAPI_SPEC') ?: null;
4139

42-
if ($specPath === null) {
40+
if (null === $specPath) {
4341
// No spec configured — use default from the package itself
4442
$specPath = $packageRoot . '/data/openapi.yaml';
45-
} elseif (! str_starts_with((string) $specPath, '/') && ! str_starts_with((string) $specPath, 'http')) {
43+
} elseif (!str_starts_with((string) $specPath, '/') && !str_starts_with((string) $specPath, 'http')) {
4644
// Relative paths: resolve from cwd when installed as dependency, package root otherwise
4745
$resolveBase = str_contains($packageRoot, DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR)
4846
? (getcwd() ?: '.')
@@ -64,7 +62,7 @@ public function __invoke(ContainerInterface $container): MiddlewareInterface
6462
if (str_starts_with((string) $specPath, 'http')) {
6563
$context = RemoteSpecificationLoader::createStreamContext();
6664
$content = file_get_contents($specPath, false, $context);
67-
if ($content === false) {
65+
if (false === $content) {
6866
throw new RuntimeException(sprintf('Failed to fetch remote spec from "%s"', $specPath));
6967
}
7068

@@ -106,7 +104,7 @@ public function __invoke(ContainerInterface $container): MiddlewareInterface
106104
);
107105
} catch (Throwable $throwable) {
108106
// Return an anonymous middleware that reports the error
109-
return new readonly class ($throwable, $specPath, $container) implements MiddlewareInterface {
107+
return new readonly class($throwable, $specPath, $container) implements MiddlewareInterface {
110108
public function __construct(
111109
private Throwable $throwable,
112110
private string $specPath,

src/Middleware/ForceMockActiveMiddleware.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Psr\Http\Message\ServerRequestInterface;
88
use Psr\Http\Server\MiddlewareInterface;
99
use Psr\Http\Server\RequestHandlerInterface;
10-
1110
use WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\OpenApiMockMiddleware;
1211

1312
class ForceMockActiveMiddleware implements MiddlewareInterface

src/Middleware/MockMiddleware/Faker/Exception/NoExample.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\Faker\Exception;
66

77
use Exception;
8-
98
use function sprintf;
109

1110
final class NoExample extends Exception

src/Middleware/MockMiddleware/Faker/Exception/NoPath.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\Faker\Exception;
66

77
use Exception;
8-
98
use function sprintf;
109

1110
final class NoPath extends Exception

src/Middleware/MockMiddleware/Faker/Exception/NoRequest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\Faker\Exception;
66

77
use Exception;
8-
98
use function sprintf;
109

1110
final class NoRequest extends Exception

src/Middleware/MockMiddleware/Faker/Exception/NoResponse.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace WebProject\PhpOpenApiMockServer\Middleware\MockMiddleware\Faker\Exception;
66

77
use Exception;
8-
98
use function sprintf;
109

1110
final class NoResponse extends Exception

0 commit comments

Comments
 (0)